-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
259 lines (218 loc) · 6.26 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
/*
* AngularJS+RequireJS project build
* @see https://github.com/josimard/angular-requirejs-seed
*/
module.exports = function(grunt) {
'use strict';
////////////////////////////////////////////////////////////////////////////////////////////
// Build configuration
var buildConfig = {
"baseUrl": "./app",
"dest": "./build/",
"js": {
"license": "/* <%= pkg.name %> <%= grunt.template.today('dd-mm-yyyy') %> */\n",
"dest":"./app/js/app.min.js"
}
};
var pkg = grunt.file.readJSON('package.json');
////////////////////////////////////////////////////////////////////////////////////////////
// Custom utilities to ease the mix of AngularJS, the RequireJS optimizer and UglifyJS2
var buildUtils = require('./tools/build-utils');
buildUtils.init(grunt);
////////////////////////////////////////////////////////////////////////////////////////////
// Default tasks
grunt.registerTask('default', ["build"]);
/*//////////////////////////////////////////////////////////////////////////////////////////
// BUILD TASK */
grunt.registerTask('build', 'Build', function()
{
// Tasks sequence
// Load and add build tasks in priority order
var taskList = buildUtils.loadTasks(["requirejs", "uglify", "css", "copy","processHtml", "customize"]);
// Get the app configuration
var requirejs = require('requirejs');
var appConfig = requirejs(buildConfig.baseUrl+"/js/config.js");
// Modify application config for the RequireJS Optimizer (Inject controller shims, etc. )
appConfig = buildUtils.configureRequireJS({
config: appConfig,
baseUrl: buildConfig.baseUrl,
dest: buildConfig.js.dest
});
var gruntConfig =
{
pkg: pkg,
/* RequireJS Optimizer */
// https://github.com/gruntjs/grunt-contrib-requirejs
// http://requirejs.org/docs/optimization.html
requirejs: {
app: {
options: appConfig.requirejs
}
},
/* UglifyJS2 */
// Custom task defined in tools/build-utils.js
// https://github.com/mishoo/UglifyJS2
uglify: {
options: {
angularPass:true,
license: buildConfig.js.license,
// http://lisperator.net/uglifyjs/compress
compress: {
unsafe:true,
warnings:false,
drop_console:false,
unused:true
}
},
main: {
files: [
// Main application file
{
src: buildConfig.js.dest, dest: buildConfig.js.dest
}
/* You can combined vendor scripts/plugins this way
{ src: [
"./app/lib/plugins/jquery.pep.js",
"./app/lib/plugins/jquery.mousewheel.js",
"./app/lib/plugins/jquery.magnific-popup.js"
], dest: "./app/lib/plugins.min.js", map: './app/lib/plugins.min.js.map'} */
]
}
},
/* Clean-css */
// Custom task defined in tools/build-utils.js
// https://github.com/GoalSmashers/clean-css
css: {
options: {
baseUrl: "./app/assets/css/",
license: buildConfig.js.license
},
main: {
files: [
{src: [
"./app/assets/css/normalize.css",
"./app/assets/css/main.css"
], dest: "./app/assets/css/main.min.css"}
]
}
},
/* Copy build */
// https://github.com/gruntjs/grunt-contrib-copy
copy: {
main: {
// http://gruntjs.com/configuring-tasks#globbing-patterns
// http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically
files: [
{expand: true, src: ['./app/index.html'], dest: buildConfig.dest},
// JS
{expand: true, src: [buildConfig.js.dest], dest: buildConfig.dest},
{expand: true, src: ['./app/js/boot.js'], dest: buildConfig.dest},
{expand: true, src: ['./app/js/config.js'], dest: buildConfig.dest},
// JS Lib
{expand: true, src: [
'./app/lib/**',
// Except:
"!./app/lib/angular/**",
"!./app/lib/plugins/**"
], dest: buildConfig.dest},
// Assets
{expand: true, src: [
'./app/assets/**',
// Except:
'!*.less',
"!./app/assets/images/sprites/**"
], dest: buildConfig.dest}
]
}
},
/* Process HTML */
// https://github.com/dciccale/grunt-processhtml
processhtml: {
options: {
},
dist: {
files: [
{src: buildConfig.baseUrl+'/index.html', dest: buildConfig.dest+'app/index.html'}
]
}
},
/* Custom task at the end of the build */
customize: {
run: function()
{
var fs = require('fs');
// Remove some generated files
fs.unlink(buildConfig.js.dest);
fs.unlink("./app/assets/css/main.min.css");
}
}
}
// Configure grunt
grunt.initConfig(gruntConfig);
// Run sub-tasks
console.log("Running tasks list: ", taskList);
grunt.task.run(taskList);
}); // End task build
/* ////////////////////////////////////////////////////////////////////////////////////////////
// SPRITESHEETS TASK
grunt.registerTask('sprites', 'Spritesheets', function()
{
// Tasks sequence
// Load and add build tasks in priority order
var taskList = ["spritesheet", "pngquant"];
// https://github.com/richardbutler/node-spritesheet
grunt.loadNpmTasks('node-spritesheet');
var gruntConfig =
{
pkg: pkg,
// CSS Spritesheets
// https://github.com/richardbutler/node-spritesheet
spritesheet: {
compile: {
options: {
outputCss: 'css/sprites.css',
selector: '.sprite',
output: {
legacy: {
pixelRatio: 1,
outputImage: 'images/sprites.png',
// Just process the non-retina files
filter: function( fullpath ) {
return fullpath.indexOf( "2x" ) === -1;
}
}//,
//retina: {
// pixelRatio: 2,
// outputImage: 'images/[email protected]',
// // Just process the retina files
// filter: function( fullpath ) {
// return fullpath.indexOf( "2x" ) >= 0;
// }
//}
}
},
files: [
{
src: './app/assets/images/sprites/**',
dest: './app/assets'
}
]
}
},
// PngQuant Custom Task
pngquant: {
main: {
files: [
{ src: './app/assets/images/sprites.png' }//,
//{ src: './app/assets/images/[email protected]' }
]
}
}
}
// Configure grunt
grunt.initConfig(gruntConfig);
// Run sub-tasks
console.log("Running tasks list: ", taskList);
grunt.task.run(taskList);
}); // End task sprites */
}