-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGruntfile.js
More file actions
182 lines (154 loc) · 4.86 KB
/
Gruntfile.js
File metadata and controls
182 lines (154 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
module.exports = function(grunt){
require('load-grunt-tasks')(grunt); //加载所有的任务
require('./src/helpers/handlebarslist.js')(grunt); //加载自定义的刷新文章列表任务
var handlebarsConf = {}//require('./src/helpers/handlebars-conf.js');
//console.log(JSON.stringify(handlebarsConf));
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
hilight_style: {
css: 'node_modules/highlight.js/styles/hybrid.css'
},
bower_concat: {
all: {
dest: 'lib/script/component.js',
cssDest: 'lib/style/component.css',
exclude: [
],
dependencies: {
'cool-dialog': 'jquery'
},
mainFiles: {
// 'highlight': ['src/highlight.pack.js','src/styles/github.css']
}
}
},
connect: {
options: {
port: 9000,
hostname: '127.0.0.1', //默认就是这个值,可配置为本机某个 IP,localhost 或域名
livereload: 35729 //声明给 watch 监听的端口
},
server: {
options: {
open: true, //自动打开网页 http://
base: [
'./' //主目录
]
}
}
},
watch: {
options: {
debounceDelay:250
},
livereload: {
options: {
livereload: '<%=connect.options.livereload%>' //监听前面声明的端口 35729
},
files: [ //下面文件的改变就会实时刷新网页
'blog/*.html',
'blog/css/*.css',
'blog/js/*.js',
'blog/img/*.{png,jpg,gif}'
]
},
livebower: {
files: ['bower_components/**'],
tasks: ['bower_concat']
},
livesaass: {
files: ['src/style/scss/*.scss'],
tasks: ['sass']
},
livestatic: {
files: ['lib/**','src/script/**','src/style/*.css'],
tasks: ['concat','uglify']
},
livepage: {
files: ['src/layout/**','src/md/**','src/page/**','src/template/**'],
tasks: ['handlebarslist','handlebarslayouts']
},
liveimg: {
files: ['src/img/**','src/data/**'],
tasks: ['copy']
}
},
sass:{
options:{
style: 'nested',
sourcemap: 'none'
},
main:{
expand: true,
cwd:'src/style/scss/',
src:['*.scss'],
dest:'src/style/',
ext:'.css'
}
},
concat: {
script: {
options:{
separator: ';'
},
src: ['<%=bower_concat.all.dest%>','src/script/*.js'],
dest: 'blog/js/main.js'
},
style: {
src: ['lib/style/*.css','<%=hilight_style.css%>','src/style/*.css'],
dest: 'blog/css/style.css'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'//添加banner
},
build: {
src: '<%=concat.script.dest%>',
dest: 'blog/js/main.min.js'
}
},
jshint: {
src: ['src/script/*.js']
},
handlebarslayouts: handlebarsConf,
copy: {
img: {
expand: true,
cwd: 'src/img/',
src: ['**'],
dest: 'blog/img/'
},
data: {
expand: true,
cwd: 'src/data/',
src: ['**'],
dest: 'blog/data/'
}
},
});
grunt.registerTask('test','just for test.',function (){
grunt.log.writeln("hahaha");
var obj = {a:1,b:2};
// grunt.file.write('src/data/test.json',JSON.stringify(obj));
// grunt.log.writeln(JSON.stringify(grunt.file.readJSON('src/data/test.json')));
});
grunt.registerTask('serve', [
'connect:server',
'watch'
]);
grunt.registerTask('compile', [
'bower_concat',
'sass',
'concat',
'uglify',
'handlebarslist',
'handlebarslayouts',
'copy'
]);
grunt.registerTask('default', function(){
grunt.log.writeln("task:");
grunt.log.ok("grunt compile : compile the blog");
grunt.log.ok("grunt serve : start a local static web server and watch daemon for developing");
});
}