-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
208 lines (185 loc) · 4.81 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
module.exports = function(grunt) {
'use strict';
require('time-grunt')(grunt);
var browserifySiteConfig = require('./browserify.config.js');
var rewriteRulesSnippet = require("grunt-connect-rewrite/lib/utils").rewriteRequest;
grunt.initConfig({
// Package Info
pkg: grunt.file.readJSON('package.json'),
// Grunt Clean
// Clear files and folders that are auto generated
// https://github.com/gruntjs/grunt-contrib-clean
clean: {
dist: {
files: [{
src: [
'<%= pkg.directory.dest %>/*'
]
}],
options:{
force: true // enables deletion fo folders outside of working directory
}
}
},
// Grunt Copy
// Copies files and folders
// https://github.com/gruntjs/grunt-contrib-copy
copy: {
dist: {
files: [{
expand: true,
cwd: '<%= pkg.directory.app %>',
dest: '<%= pkg.directory.dest %>',
src: [
'index.html',
'assets/ajax/**/*',
'assets/images/**/*',
'assets/js/**/*.html'
]
}]
}
},
// Compass
// Generates the CSS from SCSS files
// https://github.com/gruntjs/grunt-contrib-compass
compass: {
dist: {
options: {
sassDir: '<%= pkg.paths.page.scss %>',
cssDir: '<%= pkg.directory.dest %>/assets/css',
imagesDir: '<%= pkg.directory.dest %>/assets/images',
javascriptDir: '<%= pkg.directory.dest %>/assets/js',
fontsDir: '<%= pkg.directory.dest %>/assets/fonts',
relativeAssets: false,
outputStyle: 'expanded',
importPath: '<%= pkg.paths.global.scss %>' // Compass will also look at the global scss file directory
}
}
},
// Assemble
// Static site generator for Node.js, Grunt.js, and Yeoman (and soon, Gulp).
// https://github.com/assemble/assemble
assemble: {
dist: {
options: {
assets: '<%= pkg.directory.dest %>',
partials: ['<%= pkg.paths.global.partials %>','<%= pkg.paths.page.partials %>'],
layout: ['<%= pkg.paths.page.layout %>'],
data: ['<%= pkg.paths.page.data %>'],
production: true,
pages: ['<%= pkg.paths.page.pages %>']
},
files: [{
expand: true,
src: ['**/*.hbs'],
cwd: '<%= pkg.directory.app %>/views/pages/',
dest: '<%= pkg.directory.dest %>'
}]
}
},
// Browserify
// https://github.com/jmreidy/grunt-browserify
browserify: {
app: {
files: {
'<%= pkg.directory.dest %>/assets/js/app.js': ['<%= pkg.directory.app %>/assets/js/app.js']
},
options: {
// @TODO transform: ['babelify'],
alias: browserifySiteConfig,
debug: true
}
}
},
// Grunt Connect
// https://github.com/gruntjs/grunt-contrib-connect
// Used to create a static web server for dev
connect: {
options: {
port: 7777,
keepalive: true,
hostname: 'localhost'
},
// rules: [{
// from: "(^((?!css|html|js|img|fonts|\/$).)*$)",
// to: "index.html"
// }],
dist: {
options: {
open: true,
base: 'dist'
// middleware: function (connect, options) {
// return [rewriteRulesSnippet, connect["static"](require("path").resolve(options.base))];
// }
}
}
},
// Watch
// Watches for changes to specific files
// https://github.com/gruntjs/grunt-contrib-watch
watch: {
js: {
files: ['<%= pkg.paths.page.js %>','<%= pkg.paths.page.html %>'],
tasks: ['browserify'],
options: {
livereload: true
}
},
html: {
files: ['<%= pkg.paths.page.partials %>','<%= pkg.paths.page.pages %>'],
tasks: ['assemble:dist'],
options: {
livereload: true
}
},
styles: {
files: ['<%= pkg.paths.page.scss %>/**/*.scss'],
tasks: ['compass'],
options: {
livereload: true
}
},
json: {
files: ['<%= pkg.paths.page.data %>','<%= pkg.paths.page.ajax %>','<%= pkg.paths.page.html %>'],
tasks: ['copy:dist','assemble:dist'],
options: {
livereload: true
}
}
},
// Concurrent
// Allow multiple tasks to occur at once. Using this technique because it gives us flexibility in the future to add other tasks such as CONNECT.
// https://github.com/sindresorhus/grunt-concurrent
concurrent: {
dist: ['watch','connect'],
options: {
logConcurrentOutput: true
}
}
});
grunt.loadNpmTasks("grunt-connect-rewrite");
require('load-grunt-tasks')(grunt,{
pattern: ['grunt-*', 'assemble']
});
// Development grunt task
grunt.registerTask('build', [
// Cleanup Previously Generated Files
'clean:dist',
// Sass compilation
'compass:dist',
// Concat Required Browserify Modules
'browserify',
// Copy HTML and assets
'copy:dist',
// Generate HTML
'assemble:dist'
]);
// Development grunt task
grunt.registerTask('default', [
// reuse the above build task. gives us core flexibilty if we want to add more types of tasks in the future
'build',
// 'configureRewriteRules',
// Runs WATCH
'concurrent:dist'
]);
};