This repository has been archived by the owner on Dec 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
137 lines (131 loc) · 6.51 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
'use strict';
module.exports = function(grunt) {
// Set this to false if you want a non-minified build.
var USE_MINIFIED_BUILD = false;
grunt.initConfig({
autobundles: {
main: {
options: {
requireConfigModule: 'require-config'
}
}
},
// RequireJS configuration.
//
// IMPORTANT: Before changing anything at all! RTFM!
// https://github.com/jrburke/r.js/blob/master/build/example.build.js
// for an explanation of every option.
requirejs: {
main: {
options: {
// appDir and baseUrl together point to the root folder
// for all the JS modules.
appDir: 'static/jsmvc',
baseUrl: './',
// The module that contains the `requirejs.config(...)`.
mainConfigFile: 'static/jsmvc/require-config.js',
// This is the build output folder.
dir: 'static/build',
// Minification to apply, either 'uglify2' or 'none'.
optimize: USE_MINIFIED_BUILD ? 'uglify2' : 'none',
// Minification to apply to CSS. The require-css plugin
// takes care of this, so it is useless to do it here.
optimizeCss: 'none',
// These CSS settings are for require-css.
buildCSS: true,
writeCSSModule: true,
dynamicCSSBasePath: true,
// Whether to generate Source Maps for debugging.
generateSourceMaps: USE_MINIFIED_BUILD,
// Specifies files to ignore for the build.
fileExclusionRegExp: new RegExp(
'^\\.'
),
// If false, empties the build folder before each build.
keepBuildDir: false,
// When true, skips minification of modules that aren't the
// built modules.
skipDirOptimize: false,
// If true, when the optimizer merges a module into a built
// module, the standalone module will be removed from the
// build output folder.
removeCombined: true,
// Here we must define every main module, and how the
// module will be treated in the build. Refer to the docs.
modules: [
{
// This is the common build layer, we have to
// manually declare common modules to include with
// `require-config.js`.
name: 'require-config'
},
// Here are the main modules - the entry point loaded
// by pages, or via progressive loading.
{
name: 'pages/index/index'
},
{
name: 'pages/example/example'
},
{
name: 'components/progressive_load/progressive_load_example'
}
],
// Don't look at nested define() calls for dependencies
// to include in the build.
findNestedDependencies: false,
// Callback for when the build is completed.
done: function(done, output) {
// When the build is done, check for duplicated modules
// in the build. They should be optimised by putting
// into a common build layer.
// Taken from: https://github.com/gruntjs/grunt-contrib-requirejs/blob/master/README.md
var duplicates = require('rjs-build-analysis').duplicates(output);
if (Object.keys(duplicates).length > 0) {
grunt.log.subhead('Duplicates found in requirejs build:');
for (var key in duplicates) {
grunt.log.warn(duplicates[key] + ": " + key);
}
grunt.log.error('');
grunt.log.error('WARNING! Build contains ' +
'duplicated modules! Consider adding to a ' +
'common bundle/layer then into exclude: ' +
'arrays. It could be a problem if the module ' +
'has internal state!');
}
else {
grunt.log.success("Yay! No duplicated modules found in build!");
}
done();
},
// When false, strips out 'use strict' from builds as they
// will only serve to throw Strict mode errors in
// production.
useStrict: false,
preserveLicenseComments: false,
// Pragmas are build flags. When code blocks are tagged
// with a pragma via special comments, the code blocks
// will get removed from the build.
pragmas: {
stealRemove: true
},
// Converts the special comments used by CanJS and StealJS
// to mark code blocks excluded from production builds,
// into RequireJS pragmas, which achieve the same thing.
onBuildRead: function(moduleName, path, contents) {
return contents
.replace(
new RegExp('//!steal-remove-start', 'g'),
'//>>excludeStart("stealRemove", pragmas.stealRemove);')
.replace(
new RegExp('//!steal-remove-end', 'g'),
'//>>excludeEnd("stealRemove");');
}
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-requirejs-auto-bundles');
grunt.registerTask('build', ['autobundles', 'requirejs']);
};