forked from tbranyen/backbone-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
225 lines (189 loc) · 5.54 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
module.exports = function(grunt) {
"use strict";
grunt.initConfig({
// Wipe out previous builds and test reporting.
clean: ["dist/", "test/reports"],
// Run your source code through JSHint's defaults.
jshint: ["app/**/*.js"],
// This task uses James Burke's excellent r.js AMD builder to take all
// modules and concatenate them into a single file.
requirejs: {
release: {
options: {
mainConfigFile: "app/config.js",
generateSourceMaps: true,
include: ["main"],
insertRequire: ["main"],
out: "dist/source.min.js",
optimize: "uglify2",
// Since we bootstrap with nested `require` calls this option allows
// R.js to find them.
findNestedDependencies: true,
// Include a minimal AMD implementation shim.
name: "almond",
// Setting the base url to the distribution directory allows the
// Uglify minification process to correctly map paths for Source
// Maps.
baseUrl: "dist/app",
// Wrap everything in an IIFE.
wrap: true,
// Do not preserve any license comments when working with source
// maps. These options are incompatible.
preserveLicenseComments: false
}
}
},
// This task simplifies working with CSS inside Backbone Boilerplate
// projects. Instead of manually specifying your stylesheets inside the
// HTML, you can use `@imports` and this task will concatenate only those
// paths.
styles: {
// Out the concatenated contents of the following styles into the below
// development file path.
"dist/styles.css": {
// Point this to where your `index.css` file is location.
src: "app/styles/index.css",
// The relative path to use for the @imports.
paths: ["app/styles"],
// Rewrite image paths during release to be relative to the `img`
// directory.
forceRelative: "/app/img/"
}
},
// Minfiy the distribution CSS.
cssmin: {
release: {
files: {
"dist/styles.min.css": ["dist/styles.css"]
}
}
},
server: {
options: {
host: "0.0.0.0",
port: 8000
},
development: {},
release: {
options: {
prefix: "dist"
}
},
test: {
options: {
forever: false,
port: 8001
}
}
},
processhtml: {
release: {
files: {
"dist/index.html": ["index.html"]
}
}
},
// Move vendor and app logic during a build.
copy: {
release: {
files: [
{ src: ["app/**"], dest: "dist/" },
{ src: "vendor/**", dest: "dist/" }
]
}
},
compress: {
release: {
options: {
archive: "dist/source.min.js.gz"
},
files: ["dist/source.min.js"]
}
},
// Unit testing is provided by Karma. Change the two commented locations
// below to either: mocha, jasmine, or qunit.
karma: {
options: {
basePath: process.cwd(),
singleRun: true,
captureTimeout: 7000,
autoWatch: true,
reporters: ["progress", "coverage"],
browsers: ["PhantomJS"],
// Change this to the framework you want to use.
frameworks: ["mocha"],
plugins: [
"karma-jasmine",
"karma-mocha",
"karma-qunit",
"karma-phantomjs-launcher",
"karma-coverage"
],
preprocessors: {
"app/**/*.js": "coverage"
},
coverageReporter: {
type: "lcov",
dir: "test/coverage"
},
files: [
// You can optionally remove this or swap out for a different expect.
"vendor/bower/chai/chai.js",
"vendor/bower/requirejs/require.js",
"test/runner.js",
{ pattern: "app/**/*.*", included: false },
// Derives test framework from Karma configuration.
{
pattern: "test/<%= karma.options.frameworks[0] %>/**/*.spec.js",
included: false
},
{ pattern: "vendor/**/*.js", included: false }
]
},
// This creates a server that will automatically run your tests when you
// save a file and display results in the terminal.
daemon: {
options: {
singleRun: false
}
},
// This is useful for running the tests just once.
run: {
options: {
singleRun: true
}
}
},
coveralls: {
options: {
coverage_dir: "test/coverage/PhantomJS 1.9.2 (Linux)/"
}
}
});
// Grunt contribution tasks.
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-cssmin");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-compress");
// Third-party tasks.
grunt.loadNpmTasks("grunt-karma");
grunt.loadNpmTasks("grunt-karma-coveralls");
grunt.loadNpmTasks("grunt-processhtml");
// Grunt BBB tasks.
grunt.loadNpmTasks("grunt-bbb-server");
grunt.loadNpmTasks("grunt-bbb-requirejs");
grunt.loadNpmTasks("grunt-bbb-styles");
// Create an aliased test task.
grunt.registerTask("test", ["karma:run"]);
// When running the default Grunt command, just lint the code.
grunt.registerTask("default", [
"clean",
"jshint",
"processhtml",
"copy",
"requirejs",
"styles",
"cssmin",
]);
};