/
gruntfile.js
145 lines (130 loc) · 3.47 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
module.exports = function(grunt) {
/* Project configuration. */
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
bowerDir: grunt.file.readJSON('.bowerrc').directory,
// Shared JS File locations
jsfiles: {
client: [
'gruntfile.js',
'public/js/src/**/*.js',
'!<%= bowerDir %>/**'
],
server: [
'app.js',
'package.json',
'routes/*'
]
},
// The clean task removes previous built files from the dist folder.
clean: {
dist: ['public/js/dist/'],
modules: ['node_modules'],
components: ['<%= bowerDir %>']
},
jshint: {
options: {jshintrc: '.jshintrc'},
all: ['<%= jsfiles.client %>','<%= jsfiles.server %>']
},
// The stylus task compiles .styl files to css
stylus: {
compile: {
options: { compress: false },
files: {
'public/css/style.css': 'public/css/style.styl'
}
}
},
// The requirejs task traces all client-side app dependencies,
// concatenates, minifies, and creates built files in the dist folder.
requirejs: {
// shared options
options: {
baseUrl: 'public/js/src',
mainConfigFile: 'public/js/src/config.js',
name: 'config',
include: 'require-lib'
},
// development env: no minification, YAGNI?
dev: {
options: {
out: 'public/js/dist/<%= pkg.name %>.dev.js',
optimize: 'none',
useSourceUrl: true
}
},
// production env: minified
prod: {
options: {
out: 'public/js/dist/<%= pkg.name %>.prod.js',
optimize: 'uglify2',
preserveLicenseComments: false,
generateSourceMaps: true
}
}
},
// bumpup patch number
bumpup: {
files: ['package.json', 'bower.json']
},
notify: {
css: {
options: {
message: 'stylus compiled'
}
},
js: {
options: {
message: 'js compiled'
}
},
reload: {
options: {
message: 'reload sent'
}
}
},
// watches for file changes and performs tasks
watch: {
css: {
files: ['public/css/**/*.styl'],
tasks: ['stylus', 'notify:css']
},
js: {
files: [
'<%= jsfiles.client %>',
'public/js/src/views/**/*.mustache'
],
tasks: ['jshint', 'requirejs:dev', 'notify:js']
},
compiled: {
files: [
// built css
'public/css/style.css',
// built js
'public/js/dist/**/*.js',
// unit tests
'public/js/test/*.js',
// server-side views
'views/**/*.jade'
],
tasks: ['notify:reload'],
options: {
event: ['changed', 'added'],
livereload: true
}
}
}
});
/* Load task plugins */
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
/* Register primary tasks */
// `grunt build` builds fresh production js/css files
grunt.registerTask('build', ['jshint', 'clean:dist', 'stylus', 'requirejs']);
// `grunt uninstall` cleans out all external dependencies
grunt.registerTask('uninstall', ['clean']);
// `grunt dev` builds fresh distributable js/css files and starts watching
grunt.registerTask('dev', ['build', 'watch']);
// `grunt` an alias to the build task
grunt.registerTask('default', ['build']);
};