-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
357 lines (338 loc) · 11.2 KB
/
Gruntfile.js
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
"use strict";
var path = require("path");
var cssPrepareStep = require("./grunt_utils/modules/cssPrepareStep");
var requirejsPrepareStep = require("./grunt_utils/modules/requirejsPrepareStep");
var browserifyPrepareStep = require("./grunt_utils/modules/browserifyPrepareStep");
var sourceMapNameGen = require("./grunt_utils/modules/sourceMapNameGen");
var sourceMapURLGen = require("./grunt_utils/modules/sourceMapURLGen");
var replaceSuffix = require("./grunt_utils/modules/replaceSuffix");
module.exports = function(grunt) {
/**
* Feel free to configure app, copy:assets, copy:dev, copy:qa, copy:prd
* targets. Only edit the others if you know what you are doing.
*/
grunt.initConfig({
"app": {
src: "src",
dist: "dist",
bower: "bower_components",
staging: ".tmp",
configDir: "config",
configSrcDir: "build"
},
"copy": {
assets: {
files: [{
expand: true,
cwd: "<%= app.src %>",
src: ["assets/**", "images/**", "fonts/**"],
dest: "<%= app.dist %>"
}, {
expand: true,
cwd: "<%= app.bower %>/bootstrap/dist",
src: ["fonts/**"],
dest: "<%= app.dist %>"
}
]
},
dev: {
files: [{
expand: true,
cwd: "<%= app.src %>/<%= app.configSrcDir %>/<%= app.configDir %>-dev",
src: ["**"],
dest: "<%= app.src %>/<%= app.configDir %>"
}
]
},
qa: {
files: [{
expand: true,
cwd: "<%= app.src %>/<%= app.configSrcDir %>/<%= app.configDir %>-qa",
src: ["**"],
dest: "<%= app.src %>/<%= app.configDir %>"
}
]
},
prd: {
files: [{
expand: true,
cwd: "<%= app.src %>/<%= app.configSrcDir %>/<%= app.configDir %>-prd",
src: ["**"],
dest: "<%= app.src %>/<%= app.configDir %>"
}
]
},
htmlrefs: {
files: [{
expand: true,
cwd: "<%= app.src %>",
src: ["**/*.html"],
dest: "<%= app.src %>",
ext: ".htmlrefs"
}
]
},
html: {
files: [{
expand: true,
cwd: "<%= app.src %>",
src: ["**/*.htmlrefs"],
dest: "<%= app.dist %>",
ext: ".html"
}
]
},
jsSourceMap: {}
},
"htmlrefs": {
build: {
src: ["<%= app.src %>/**/*.htmlrefs"]
}
},
"useminPreparePrepare": {
html: "<%= app.src %>/**/*.htmlrefs",
options: {
src: "<%= app.src %>",
dest: "<%= app.dist %>",
staging: "<%= app.staging %>",
flow: {
steps: {
"js": ["uglifyjs"],
"css": [cssPrepareStep, "cssmin"],
"amd": [requirejsPrepareStep, "uglifyjs"],
"commonjs": [browserifyPrepareStep, "uglifyjs"]
},
post: {}
}
}
},
"requirejsPrepare": {
generated: {
// Options will be copied to requirejs options. baseUrl,
// mainConfigFile, name and out properties will be automatically
// generated by this task. However if define them here, they
// will be override. Paths will be normalized from baseUrl so
// that you can define it here relative to Gruntfile.js If you
// MUST have more than one target, use configFilesToTarget to
// copy files generated by useminPrepare to another target then
// you will be able to run targets other than generated.
options: {
optimize: "none",
paths: {
requireLib: "bower_components/almond/almond"
},
include: "requireLib"
}
}
},
"browserifyPrepare": {
// If you MUST have more than one target, use configFilesToTarget to
// copy files generated by useminPrepare to another target then you
// will be able to run targets other than generated. Options will be
// copied straight to browserify task.
generated: {},
},
"replaceUseminType": {
generated: {
}
},
"usemin": {
html: ["<%= app.dist %>/**/*.html"],
options: {
assetsDirs: ["<%= app.dist %>"]
}
},
"configFilesToTarget": {
genSourceMap: {
options: {
targets: ["genSourceMap"],
tasks: ["uglify"]
}
}
},
"uglify": {
options: {
preserveComments: "some"
},
genSourceMap: {
options: {
// Due to the way uglify works, source path is pretty messed
// up. Please keep that in mind.
sourceMap: sourceMapNameGen,
sourceMappingURL: sourceMapURLGen
}
}
},
"cssPrepare": {
generated: {}
},
"cssmin": {
generated: {},
options: {
keepSpecialComments: "*"
}
},
"htmlmin": {
build: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: [{
expand: true,
dest: ".",
src: ["<%= app.dist %>/**/*.html"]
}]
}
},
"sourceCopyPrepare": {
jsSourceMap: {
options: {
srcTask: "uglify",
srcTaskTarget: "genSourceMap"
}
}
},
"configToTask": {
uglifyToConcat: {
options: {
from: "uglify",
to: "concat"
}
}
},
"clean": {
postBuild: ["<%= app.staging %>", "<%= app.src %>/**/*.htmlrefs"],
clean: ["<%= app.dist %>", "<%= app.src %>/<%= app.configDir %>"]
},
"watch": {
devCommonJs: {
files: [
"<%= app.src %>/**/*",
"!<%= app.src %>/**/*.htmlrefs",
// Don't forget to add your config directory to ignore list.
// If you don't have a config directory, remove this line.
"!<%= app.src %>/<%= app.configDir %>/**/*"
],
tasks: ["devCommonJs"],
options: {
interrupt: true
}
},
// This target can be used when you actively changing configs,
// otherwise it's pretty pointless.
dev: {
files: [
"<%= app.src %>/<%= app.configSrcDir %>/**/*"
],
tasks: ["dev"],
options: {
interrupt: true
}
}
}
});
grunt.loadTasks("grunt_utils/tasks");
grunt.loadNpmTasks("grunt-usemin");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-sass");
grunt.loadNpmTasks("grunt-contrib-cssmin");
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks("grunt-htmlrefs");
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask("prebuild", [
"copy:htmlrefs",
"htmlrefs:build",
"copy:html",
"copy:assets",
"useminPreparePrepare",
"useminPrepare"
]);
grunt.registerTask("amdGen", [
"requirejsPrepare:generated"
]);
grunt.registerTask("commonJsGen", [
"browserifyPrepare:generated"
]);
grunt.registerTask("cssGen", [
"cssPrepare:generated",
"copy:generated",
"less:generated",
"sass:generated"
]);
grunt.registerTask("minExternal", [
"uglify:generated",
"cssmin:generated"
]);
// Too bad there's no source map gen for CSS with grunt-contrib-cssmin.
grunt.registerTask("minExternalGenSourceMap", [
"configFilesToTarget:genSourceMap",
"uglify:genSourceMap",
"cssmin:generated",
"sourceCopyPrepare:jsSourceMap",
"copy:jsSourceMap"
]);
grunt.registerTask("useminWrapped", [
"replaceUseminType:generated",
"usemin"
]);
grunt.registerTask("finalize", [
"clean:postBuild"
]);
grunt.registerTask("buildAll", [
"prebuild",
"amdGen",
"commonJsGen",
"cssGen",
"minExternal",
"useminWrapped",
"htmlmin:build",
"finalize"
]);
grunt.registerTask("buildGenSourceMap", [
"prebuild",
"amdGen",
"commonJsGen",
"cssGen",
"minExternalGenSourceMap",
"useminWrapped",
"htmlmin:build",
"finalize"
]);
/****************** Actual tasks you should use to build ******************/
grunt.registerTask("dev", [
"copy:dev"
]);
// This is a special dev build task aimed for projects developed with
// CommonJS. Due to the fact that CommonJS modules are not browser
// compatible in their raw forms, in order to run them in a browser, they
// must be processed by browserify. This task runs the minimun amount of
// process to help wrap CommonJS modules and get them to a runnable state.
// That also means you will have to run your project from dist directory
// instead. See watch task for better convenience.
grunt.registerTask("devCommonJs", [
"copy:dev",
"prebuild",
"commonJsGen",
"cssGen",
"configToTask:uglifyToConcat",
"concat:generated",
"useminWrapped",
"finalize"
]);
grunt.registerTask("prd", [
"clean",
"copy:prd",
"buildAll"
]);
grunt.registerTask("qa", [
"clean",
"copy:qa",
"buildGenSourceMap"
]);
grunt.registerTask("default", ["dev"]);
}