This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
220 lines (180 loc) · 3.88 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
var fs = require("fs")
/**
* Configuration part of following grunt tasks
*/
var STYLE_FILES = [
'styles/screen.styl'
]
var JS_FILES = [
'js/index.js'
]
var DIST_FOLDER = 'build'
var HASH_SOURCES = [
DIST_FOLDER + '/*.css',
DIST_FOLDER + '/*.js'
]
var WATCH_FILES = [
DIST_FOLDER + '/*'
]
/**
* Grunt project itself with defined tasks and theirs options
*/
module.exports = function(grunt) {
grunt.initConfig({
// Clean dist folder from obsolote files
clean: {
dist: DIST_FOLDER + '/*'
},
copy: {
images: {
src: 'img/**',
dest: DIST_FOLDER + '/'
}
},
// Compile Stylus styles into CSS
stylus: {
dev: {
options: {
'include css': true,
compress: false
},
expand: true,
flatten: true,
src: STYLE_FILES,
dest: DIST_FOLDER + '/',
ext: '.css'
},
dist: {
options: {
'include css': true
},
expand: true,
flatten: true,
src: STYLE_FILES,
dest: DIST_FOLDER + '/',
ext: '.css'
}
},
// Concat and minify JavaScript files to signel app.js file
browserify: {
options: {
transform: ['browserify-shim', 'uglifyify'],
external: ['jquery']
},
dev: {
options: {
debug: true,
transform: ['browserify-shim']
},
src: JS_FILES,
dest: DIST_FOLDER + '/app.js'
},
dist: {
src: JS_FILES,
dest: DIST_FOLDER + '/app.js'
},
ie8: {
src: 'js/ie8.js',
dest: DIST_FOLDER + '/ie8.js'
}
},
// Generate static HTML files from Handlebars templates
assemble: {
options: {
data: 'templates/_data/**/*.json',
layoutdir: 'templates/_layouts',
layoutext: '.hbs',
layout: 'default',
partials: 'templates/_partials/**/*.hbs'
},
dist: {
files: {
'build/': ['templates/*.hbs']
}
}
},
// Minify CSS even more, every byte counts
cssmin: {
dist: {
expand: true,
cwd: DIST_FOLDER + '/',
src: '*.css',
dest: DIST_FOLDER + '/'
}
},
// Rename resource files based on theirs content to prevent cache colisions
hashres: {
dist: {
// expand: true,
src: HASH_SOURCES,
dest: DIST_FOLDER + '/*.html'
}
},
// Development mode with resources auto reload and browser actions synchronizations
browserSync: {
dev: {
options: {
watchTask: true,
debugInfo: true,
// Only static files
server: {
baseDir: 'build'
},
// Dynamic files (PHP etc) - proxy to running server
// proxy: 'localhost',
ghostMode: {
clicks: true,
scroll: true,
links: false,
forms: true
}
},
bsFiles: {
src: WATCH_FILES
}
}
},
// Watch sources for change and compile them. Starts Livereload server as fallback of browserSync.
watch: {
options: {
spawn: false
},
images: {
files: 'img/*',
tasks: 'copy:images'
},
styles: {
files: 'styles/**/*.styl',
tasks: 'stylus:dev'
},
js: {
files: 'js/**/*.js',
tasks: 'browserify:dev'
},
templates: {
files: 'templates/**',
tasks: 'assemble:dist'
},
livereload: {
files: WATCH_FILES,
options: {
livereload: true
}
}
}
})
// Load plugins
grunt.loadNpmTasks('grunt-assemble')
grunt.loadNpmTasks('grunt-browser-sync')
grunt.loadNpmTasks('grunt-browserify')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-contrib-copy')
grunt.loadNpmTasks('grunt-contrib-cssmin')
grunt.loadNpmTasks('grunt-contrib-stylus')
grunt.loadNpmTasks('grunt-contrib-watch')
grunt.loadNpmTasks('grunt-hashres')
grunt.loadNpmTasks('grunt-notify')
// Register tasks
grunt.registerTask('default', ['clean:dist', 'copy:images', 'assemble:dist', 'stylus:dist', 'browserify:dist', 'browserify:ie8', 'cssmin:dist', 'hashres:dist'])
grunt.registerTask('dev', ['clean:dist', 'copy:images', 'assemble:dist', 'stylus:dev', 'browserify:dev', 'browserify:ie8', 'browserSync:dev', 'watch'])
}