-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
executable file
·385 lines (373 loc) · 13.7 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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
'use strict';
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Show grunt task time
require('time-grunt')(grunt);
// Configurable paths for the app
var appConfig = {
app: 'app',
dist: 'dist',
dna: '../angular-frontend-dna/app',
tmp: '.tmp',
tmpCompile: '.tmp/compile',
};
// https://stackoverflow.com/questions/24283653/angularjs-html5mode-using-grunt-connect-grunt-0-4-5/24384293#24384293
var modRewrite = require('connect-modrewrite');
// Grunt configuration
grunt.initConfig({
// Project settings
paths: appConfig,
// The grunt server settings
connect: {
options: {
port: 9000,
hostname: 'localhost',
livereload: 35729
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
modRewrite(['^/([^\\.]+)$ /#!/$1 [NC,NE,R=302]']),
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.dna),
connect.static(appConfig.app)
];
}
}
},
dist: {
options: {
open: true,
livereload: false,
base: '<%= paths.dist %>'
}
}
},
// Compile less to css
less: {
development: {
options: {
compress: true,
optimization: 2
},
files: {
".tmp/styles/style.css": "<%= paths.tmpCompile %>/less/style.less"
}
}
},
// Watch for changes in live edit
watch: {
less: {
files: ['<%= paths.app %>/less/*.less'],
tasks: ['copy:less', 'less'],
options: {
nospawn: true,
livereload: '<%= connect.options.livereload %>'
},
},
lessDna: {
files: ['<%= paths.dna %>/less/*.less'],
tasks: ['copy:lessDna', 'less'],
options: {
nospawn: true,
livereload: '<%= connect.options.livereload %>'
},
},
js: {
files: ['<%= paths.app %>/scripts/{,*/}*.js','<%= paths.dna %>/{,*/}{,*/}*.js'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= paths.app %>/**/*.html','<%= paths.dna %>/**/*.html',
'.tmp/styles/{,*/}*.css',
'<%= paths.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}','<%= paths.dna %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
// Annotate angular source code with string-injection based syntax to be able to use uglify properly below
ngAnnotate: {
options: {
singleQuotes: true
},
dist: {
files: {
'.tmp/concat/scripts/vendor.js': ['.tmp/concat/scripts/vendor.js'],
'.tmp/concat/scripts/scripts.js': ['.tmp/concat/scripts/scripts.js']
}
}
},
// If you want to turn on uglify you will need write your angular code with string-injection based syntax
// For example this is normal syntax: function exampleCtrl ($scope, $rootScope, $location, $http){}
// And string-injection based syntax is: ['$scope', '$rootScope', '$location', '$http', function exampleCtrl ($scope, $rootScope, $location, $http){}]
// Note: Taken care of by ngAnnotate above
uglify: {
options: {
mangle: false,
sourceMap: true
}
},
concat: {
options: {
separator: grunt.util.linefeed + ';' + grunt.util.linefeed
}
},
// Clean dist folder
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'.merged-app',
'<%= paths.dist %>/{,*/}*',
'!<%= paths.dist %>/.git*'
]
}]
},
server: '.tmp'
},
copy: {
// Merges files from the dna and bower_components folder to the a merged app folder, similar to the one served during dev
preBuildMerge: {
files: [
{
cwd: '<%= paths.app %>/',
expand: true,
filter: 'isFile',
src: [
'**',
'!.gitkeep'
],
dest: '.merged-app/'
},
{
cwd: '<%= paths.dna %>/',
expand: true,
filter: 'isFile',
src: [
'**',
'!.gitkeep'
],
dest: '.merged-app/'
},
{
cwd: 'bower_components/',
expand: true,
filter: 'isFile',
src: [
'**',
'!.gitkeep'
],
dest: '.merged-app/bower_components'
}
]
},
// Copies main app less styles to temporary compile directory
less: {
files: [
{
cwd: '<%= paths.app %>/../bower_components/bootstrap/less/',
expand: true,
filter: 'isFile',
src: [
'**',
'!.gitkeep'
],
dest: '<%= paths.tmpCompile %>/../bower_components/bootstrap/less/'
},
{
cwd: '<%= paths.app %>/less/',
expand: true,
filter: 'isFile',
src: [
'**',
'!.gitkeep'
],
dest: '<%= paths.tmpCompile %>/less/'
}
]
},
// Copies dna less styles to temporary compile directory
lessDna: {
files: [
{
cwd: '<%= paths.dna %>/less/',
expand: true,
filter: 'isFile',
src: [
'**',
'!.gitkeep'
],
dest: '<%= paths.tmpCompile %>/less/'
}
]
},
// Copies remaining files to places other tasks can use
dist: {
files: [
{
expand: true,
dot: true,
cwd: '.merged-app/',
dest: '<%= paths.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'*.html', '**/*.html', '!bower_components/**/*.html', '!scripts/**/*.html',
'fonts/*.*',
/*
'styles/patterns/*.*',
'bower_components/select2/dist/css/select2.min.css', // manually included due to breakage upon build
'bower_components/iCheck/skins/* /*.*', // manually included due to breakage upon build
'bower_components/angular-bootstrap-colorpicker/css/colorpicker.css', // manually included due to breakage upon build
'bower_components/fullcalendar/dist/fullcalendar.css', // manually included due to breakage upon build
'bower_components/intro.js/introjs.css', // manually included due to breakage upon build
'bower_components/auth0-lock/build/auth0-lock.min.js', // manually included due to breakage upon build
'bower_components/jquery/dist/jquery.min.js', // manually included due to breakage of optimizely-logic upon build
*/
'scripts/dc/*.*', // for demo purposes
'scripts/env.js',
'images/{,*/}*.*'
]
},
{
// To be able to debug using source maps
expand: true,
dot: true,
cwd: '.tmp',
dest: '<%= paths.dist %>/.tmp',
src: [
'**'
]
},
{
// For lazy-loading of resources to work in production
// TODO: Trim this to only the used resources to speed up
// production build and deploy
expand: true,
dot: true,
cwd: '.merged-app/',
dest: '<%= paths.dist %>',
src: [
'**/*.{js,css}'
]
},
{
expand: true,
dot: true,
cwd: 'bower_components/fontawesome',
src: ['fonts/*.*'],
dest: '<%= paths.dist %>'
},
{
expand: true,
dot: true,
cwd: 'bower_components/bootstrap',
src: ['fonts/*.*'],
dest: '<%= paths.dist %>'
},
]
},
styles: {
expand: true,
cwd: '<%= paths.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
},
stylesDna: {
expand: true,
cwd: '<%= paths.dna %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
// Renames files for browser caching purposes
filerev: {
dist: {
src: [
'<%= paths.dist %>/scripts/{,*/}*.js',
'<%= paths.dist %>/styles/{,*/}*.css',
//'<%= paths.dist %>/fonts/*'
]
}
},
htmlmin: {
dist: {
options: {
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeCommentsFromCDATA: true,
removeOptionalTags: true
},
files: [{
expand: true,
cwd: '<%= paths.dist %>',
src: ['*.html', '**/*.html', '!bower_components/**/*.html', '!scripts/**/*.html'],
dest: '<%= paths.dist %>'
}]
}
},
useminPrepare: {
html: '.merged-app/index.html',
options: {
dest: 'dist'
}
},
usemin: {
html: ['dist/index.html']
}
});
grunt.registerTask('dumpConfig', 'Dump grunt config', function(arg) {
grunt.log.writeln(JSON.stringify(grunt.config(), null, 2));
});
// Run live version of app
grunt.registerTask('live', [
'clean:server',
'copy:less',
'copy:lessDna',
'less',
'copy:styles',
'copy:stylesDna',
'connect:livereload',
'watch'
]);
// Run build version of app
grunt.registerTask('server', [
'build',
'connect:dist:keepalive'
]);
// Build version for production
grunt.registerTask('build', [
'clean:dist',
'copy:less',
'copy:lessDna',
'less',
'copy:styles',
'copy:stylesDna',
'copy:preBuildMerge',
'useminPrepare',
'dumpConfig',
'concat',
'copy:dist',
'cssmin',
'ngAnnotate:dist',
'uglify',
'filerev',
'usemin',
'htmlmin'
]);
};