-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
212 lines (186 loc) · 6.17 KB
/
Gruntfile.js
File metadata and controls
212 lines (186 loc) · 6.17 KB
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
///////////////////////////////////////////////
// Configuration Options
///////////////////////////////////////////////
var uglifyWhenWatching = false;
var sassOutputStyle = 'expanded'; // expanded | nested | compact | compressed
// Require any extras that we might need.
var fs = require('fs');
///////////////////////////////////////////////
// Helper Functions
///////////////////////////////////////////////
function merge(source, target) {
for(var key in source) {
if (source.hasOwnProperty(key)) {
target[key] = source[key];
}
}
}
// Main Grunt section
module.exports = function(grunt) {
var config = {
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
// jQuery
'js/vendor/jquery-1.11.1.min.js',
// Bootstrap individual components (load order matters)
'bootstrap/assets/javascripts/bootstrap/affix.js',
'bootstrap/assets/javascripts/bootstrap/alert.js',
'bootstrap/assets/javascripts/bootstrap/button.js',
'bootstrap/assets/javascripts/bootstrap/carousel.js',
'bootstrap/assets/javascripts/bootstrap/collapse.js',
'bootstrap/assets/javascripts/bootstrap/dropdown.js',
'bootstrap/assets/javascripts/bootstrap/tab.js',
'bootstrap/assets/javascripts/bootstrap/transition.js',
'bootstrap/assets/javascripts/bootstrap/scrollspy.js',
'bootstrap/assets/javascripts/bootstrap/modal.js',
'bootstrap/assets/javascripts/bootstrap/tooltip.js',
'bootstrap/assets/javascripts/bootstrap/popover.js',
// OR simply include all Bootstrap
// 'bootstrap/assets/javascripts/bootstrap.js',
// Blanket Vendor Scripts
'js/vendor/*.js', // Include rest of vendor scripts in no particular order.
'!js/vendor/html5shiv.js', // [!] Needs to be in the head to work properly.
'!js/vendor/respond.min.js', // [!] Needs to be in the head to work properly.
'js/*.js', // All .js files.
'js/scripts.js', // Add the scripts.js file last.
'!js/all.js', // [!] Do not concat all.js
'!js/all.min.js' // [!] Do not concat all.min.js
],
dest: 'js/all.js',
},
},
sass: {
dist: {
options: {
style: sassOutputStyle
},
files: {
'css/styles.css': 'sass/main.scss'
}
}
},
watch: {
scripts: {
files: [
// Run the concat task when any of these files change:
'js/**/*.js', // all of the .js files
'!js/all.js' // [!] We don't want to watch the generated file.
],
tasks: ['concat']
},
css: {
// Run the sass task when any of these files change:
files: [
'sass/**/*.scss' // all of the .scss files.
],
tasks: ['sass']
}
},
browserSync: {
dev: {
bsFiles: {
src : [
// Livereload when any of these files change:
'css/**/*.css', // compiled CSS
'js/**/all*.js', // concatenated/minified JS
'**/*.html', // any HTML files
'**/*.php' // any PHP files
]
},
options: {
watchTask: true,
server: './',
port: 8000,
snippetOptions: {
// Inject the snippet at the end of the body tag.
// this helps with issues related to IE conditional
// comments getting in the way.
rule: {
match: /<\/body>/i,
fn: function (snippet, match) {
return snippet + match;
}
}
}
}
}
}
};
///////////////////////////////////////////////
// Tasks
///////////////////////////////////////////////
var defaultTasks = [
'browserSync',
'concat',
'sass'
];
///////////////////////////////////////////////
// Conditional for CoffeeScript
///////////////////////////////////////////////
if (fs.existsSync('coffee')) {
var coffeeConfig = {
coffee: {
compile: {
expand: true,
flatten: true,
src: ['coffee/*.coffee'],
dest: 'js/',
ext: '.js'
}
}
};
var coffeeWatch = {
coffee: {
files: ['coffee/**.coffee'], // Watch the coffee files.
tasks: ['coffee'] // Run the coffee processor.
}
};
merge(coffeeConfig, config); // Add the coffee configuration.
merge(coffeeWatch, config.watch); // Add the coffee watcher.
defaultTasks.unshift('coffee');
grunt.loadNpmTasks('grunt-contrib-coffee');
}
///////////////////////////////////////////////
// Conditional for Uglification
///////////////////////////////////////////////
if(uglifyWhenWatching){
var uglifyConfig = {
uglify: {
dist: {
files: {
'js/all.min.js': ['js/all.js']
}
}
}
};
merge(uglifyConfig, config); // Add the uglify configuration.
config.watch.scripts.tasks.push('uglify'); // Add uglify to the concat watcher.
defaultTasks.push('uglify');
grunt.loadNpmTasks('grunt-contrib-uglify');
}
///////////////////////////////////////////////
// Where we tell Grunt we plan to use
// the plug-ins configured above
///////////////////////////////////////////////
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-browser-sync');
// Initialize the Grunt configuration
grunt.initConfig(config);
///////////////////////////////////////////////
// What will initialize when we type
// "grunt" into the terminal.
///////////////////////////////////////////////
//
// grunt
// grunt uglify - to minify the JavaScript
//
// Minification of JavaScript is kept separate to keep the
// save -> refresh cycle fast. Run `grunt uglify` before switching
// the all.js script tag to all.min.js
defaultTasks.push('watch'); // Watch blocks, so it must be pushed last.
grunt.registerTask('default', defaultTasks);
};