/
Gruntfile.js
181 lines (164 loc) · 7.02 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
module.exports = function (grunt) {
// Project configuration
grunt.initConfig({
// you can read in JSON files, which are then set as objects. We use this below with banner
pkg: grunt.file.readJSON('package.json'),
// setup some variables that we'll use below
rootAssetsDir: 'assets',
webDir: 'web',
targetAssetsDir: '<%= webDir %>/assets',
copy: {
main: {
files: [
{
expand: true,
src: [
// copy /assets to /web/assets
'<%= rootAssetsDir %>/**',
// but don't copy the SASS source files, not needed!
'!<%= rootAssetsDir %>/sass/**',
// and don't copy the config directory
'!<%= rootAssetsDir %>/config/**'
],
dest: '<%= webDir %>'
}
]
}
},
clean: {
build: {
src: ['<%= targetAssetsDir %>/**']
}
},
requirejs: {
// creates a "main" requirejs sub-task (grunt requirejs:main)
// we *could* have other sub-tasks for using requirejs with other
// files or configuration
main: {
options: {
mainConfigFile: '<%= targetAssetsDir %>/js/common.js',
appDir: '<%= rootAssetsDir %>',
baseUrl: './js',
dir: '<%= targetAssetsDir %>',
// will be taken care of with compass
optimizeCss: "none",
// will be taken care of with an uglify task directly
optimize: "none",
/**
* The list of modules that should have their dependencies packed into them.
*
* For each module listed here, Require.js will read
* that modules dependencies and package them in the
* file. It will additionally add in any modules (and
* their dependencies) specified in the "include" and
* exclude any modules (and their dependencies) specified
* in "exclude".
*/
modules: [
// First set up the common build layer.
{
// module names are relative to baseUrl
name: 'common',
// List common dependencies here. Only need to list
// top level dependencies, "include" will find
// nested dependencies inside each of these
include: ['jquery', 'domReady', 'bootstrap']
},
// Now set up a build layer for each page, but exclude
// the common one. "exclude" will exclude nested
// the nested, built dependencies from "common". Any
// "exclude" that includes built modules should be
// listed before the build layer that wants to exclude it.
// "include" the appropriate "app/main*" module since by default
// it will not get added to the build since it is loaded by a nested
// require in the page*.js files.
{
// module names are relative to baseUrl/paths config
name: 'app/homepage',
exclude: ['common']
}
]
}
}
},
uglify: {
options: {
// a cute way to put a banner on each uglified file
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
files: [
{
expand: true,
cwd: '<%= targetAssetsDir %>/js/',
src: ['**/*.js'],
dest: '<%= targetAssetsDir %>/js/'
}
]
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
reporter: require('jshint-stylish')
},
all: [
'Gruntfile.js',
'<%= targetAssetsDir %>/js/{,*/}*.js'
]
},
// use compass to compile everything in the "sass" directory into "css"
compass: {
// the "production" build subtask (grunt compass:dist)
dist: {
options: {
// SASS and CSS paths are defined in the config
config: '<%= rootAssetsDir %>/config/compass.rb',
environment: 'production',
outputStyle: 'compressed'
}
},
// the "development" build subtask (grunt compass:dev)
dev: {
options: {
// SASS and CSS paths are defined in the config
config: '<%= rootAssetsDir %>/config/compass.rb',
outputStyle: 'expanded'
}
}
},
// run "Grunt watch" and have it automatically update things when files change
watch: {
// watch all JS files and run jshint
scripts: {
files: ['<%= rootAssetsDir %>/js/**'],
tasks: ['copy', 'jshint'],
options: {
spawn: false
}
},
// watch all .scss files and run compass
compass: {
files: '<%= rootAssetsDir %>/sass/*.scss',
tasks: ['copy', 'compass:dev'],
options: {
spawn: false
}
}
}
});
// Load tasks from our external plugins. These are what we're configuring above
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
// sub-task that copies assets to web/assets, and also cleans some things
grunt.registerTask('copy:assets', ['clean:build', 'copy']);
// the "default" task (e.g. simply "Grunt") runs tasks for development
grunt.registerTask('default', ['copy:assets', 'jshint', 'compass:dev']);
// register a "production" task that sets everything up before deployment
grunt.registerTask('production', ['copy:assets', 'jshint', 'requirejs', 'uglify', 'compass:dist']);
};