-
Notifications
You must be signed in to change notification settings - Fork 7
/
Gruntfile.js
150 lines (133 loc) · 4.27 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
module.exports = function(grunt) {
// build config command-line keys
var configKey = grunt.option('config') || 'default';
var devConfig = grunt.option('dev');
// files and settings derived from build config
var lessConfigFile = "config-" + configKey + ".less";
var jsConfigFile = "config-" + configKey + ".js";
// FIXME: configuration repeated below in the cdndeps key; the dependency js files should be obtained directly from the key below
var jsDependencies = require("grunt-cdndeps")({
production: false,
src: "package.json",
dest: "build/dependencies"
});
var uglifyTask = devConfig ? 'copy:uglify' : 'uglify';
grunt.initConfig({
buildOptions: {
buildPath: "build",
distPath: "dist"
},
// compiles LESS files
less: {
compile: {
options: {
strictMath: true,
imports: {
less: [lessConfigFile]
}
},
files: [
{
expand: true,
cwd: 'app/less',
src: ['base.less', 'widgets/*.less'],
dest: '<%= buildOptions.buildPath %>/less/',
ext: '.css'
}
]
}
},
// concatenates and minifies CSS files
cssmin: {
combine: {
files: {
"<%= buildOptions.distPath %>/application.min.css": [
"app/css/font_awesome.css", "<%= buildOptions.buildPath %>/less/base.css",
"app/css/widgets/*.css", "<%= buildOptions.buildPath %>/less/widgets/*.css"]
}
}
},
// downloads the runtime JavaScript dependencies of the project
cdndeps: {
options: {
src: "package.json",
dest: "<%= buildOptions.buildPath %>/dependencies"
}
},
// finds Handlebars templates and precompiles them into functions
emberTemplates: {
options: {
templateName: function(sourceFile) {
return sourceFile.replace(/app\/templates\//, '');
}
},
"<%= buildOptions.buildPath %>/templates/templates.js": ["app/templates/**/*.hbs"]
},
// concatenates JavaScript code into one file
neuter: {
options: {
template: "{%= src %}",
includeSourceMap: true,
sourceRoot: ".."
},
"<%= buildOptions.buildPath %>/application.js": jsDependencies.concat([
"app/" + jsConfigFile,
"app/app.js",
"<%= buildOptions.buildPath %>/templates/templates.js"])
},
// minifies the JavaScript code
uglify: {
options: {
sourceMap: true,
sourceMapIn: "<%= buildOptions.buildPath %>/application.js.map",
sourceMapName: "<%= buildOptions.distPath %>/application.min.js.map",
mangle: { except: ["$super"] }
},
"<%= buildOptions.distPath %>/application.min.js": "<%= buildOptions.buildPath %>/application.js"
},
// copies all files from one place to another
copy: {
uglify: {
files: {
"<%= buildOptions.distPath %>/application.min.js":
"<%= buildOptions.buildPath %>/application.js",
"<%= buildOptions.distPath %>/application.min.js.map":
"<%= buildOptions.buildPath %>/application.js.map"
}
}
},
// watches files for changes
watch: {
build_code: {
files: ['package.json'],
tasks: ['cdndeps', 'emberTemplates', 'neuter', uglifyTask]
},
application_code: {
files: ['app/**/*.js'],
tasks: ['neuter', uglifyTask]
},
css_stylesheets: {
files: ['app/css/**/*.css'],
tasks: ['cssmin']
},
less_stylesheets: {
files: ['app/less/**/*.less'],
tasks: ['less', 'cssmin']
},
handlebars_templates: {
files: ['app/templates/**/*.hbs'],
tasks: ['emberTemplates', 'neuter', uglifyTask]
}
}
});
grunt.loadNpmTasks('assemble-less');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-cdndeps');
grunt.loadNpmTasks('grunt-ember-templates');
grunt.loadNpmTasks('grunt-neuter');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('build', ['less', 'cssmin', 'cdndeps', 'emberTemplates', 'neuter', uglifyTask]);
grunt.registerTask('default', ['build', 'watch']);
};