This repository has been archived by the owner on Apr 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
220 lines (205 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
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
module.exports = function(grunt) {
grunt.initConfig({
autoprefixer: {
build: {
src: 'dist/style.css',
dest: 'dist/style.css'
},
options: {
// available options:
// https://github.com/nDmitry/grunt-autoprefixer#options
browsers: [ '> 1%', 'last 2 versions' ],
}
},
clean: {
// clean `distributable` folder (most probably before triggering a new build)
dist: ['dist'],
// clean non-used artifacts from the `distributable` folder after the build
afterMin: ['dist/style.css', 'dist/main.js'],
site: ['_site/*.css', '_site/*.js', '_site/img/']
},
copy: {
// copy over single files from the root directory to the `distributable` folder
// add assets if needed
main: {
files: [
{expand: true, src: ['index.html'], dest: 'dist/', filter: 'isFile'},
{expand: true, src: ['last-minute.html'], dest: 'dist/', filter: 'isFile'},
{expand: true, src: ['feedback.html'], dest: 'dist/', filter: 'isFile'},
{expand: true, src: ['codeofconduct.html'], dest: 'dist/', filter: 'isFile'},
{expand: true, src: ['robots.txt'], dest: 'dist/', filter: 'isFile'},
{expand: true, src: ['conference.ics'], dest: 'dist/', filter: 'isFile'},
{expand: true, src: ['.htaccess'], dest: 'dist/', filter: 'isFile'},
{expand: true, src: ['favicon.ico'], dest: 'dist/', filter: 'isFile'},
{expand: true, src: ['templates/*.html'], dest: 'dist/', filter: 'isFile'},
{expand: true, src: ['node_modules/photoswipe/dist/default-skin/*.{svg,png,gif}'], dest: 'dist/', flatten: true, filter: 'isFile'}
]
},
dist: {
files: [
{expand: true, cwd: 'dist', src: ['img/**'], dest: '_site/'},
{expand: true, cwd: 'dist', src: ['slides/**'], dest: '_site/'},
{expand: true, cwd: 'dist', src: ['*.html'], dest: '_site/'},
{expand: true, cwd: 'dist', src: ['*.js'], dest: '_site/'},
{expand: true, cwd: 'dist', src: ['*.css'], dest: '_site/'},
{expand: true, cwd: 'dist', src: ['.htaccess', 'conference.ics', 'robots.txt', 'favicon.ico'], dest: '_site/'}
]
}
},
concat: {
// concatenate js files (manually because of keeping the order intact)
js: {
src: [
'node_modules/jquery/dist/jquery.js',
'vendor/modal.js',
'node_modules/photoswipe/dist/photoswipe.js',
'node_modules/photoswipe/dist/photoswipe-ui-default.js',
'main.js'
],
dest: 'dist/main.js'
},
// concatenate css files (manually because of keeping the order intact)
css: {
src: [
'vendor/normalize.css',
'vendor/modal.css',
'vendor/zoom.css',
'node_modules/photoswipe/dist/photoswipe.css',
'node_modules/photoswipe/dist/default-skin/default-skin.css',
'style.css'
],
dest: 'dist/style.css'
}
},
// minify the contents of the index.html file (in the `distributable` folder)
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
uglifyJS: true
},
files: {
'dist/index.html': 'dist/index.html',
'dist/last-minute.html': 'dist/last-minute.html',
'dist/codeofconduct.html': 'dist/codeofconduct.html',
'dist/templates/photoswipe.html': 'dist/templates/photoswipe.html',
'dist/feedback.html': 'dist/feedback.html'
}
}
},
// minify the contents of the concatenated css file (in the `distributable` folder)
cssmin: {
combine: {
files: {
'dist/style.min.css': ['dist/style.css']
}
}
},
// minify the contents of the concatenated js file (in the `distributable` folder)
uglify: {
build: {
src: 'dist/main.js',
dest: 'dist/main.min.js'
}
},
// revision the asset files names (in the `distributable` folder)
// patttern: ORIGINALFILENAME.{$HASH}.EXTENSION
filerev: {
options: {
encoding: 'utf8',
algorithm: 'md5',
length: 8
},
images: {
src: ['dist/img/**/*.{jpg,jpeg,gif,png,webp,svg}', '!**/favicon/**', '!**/touch/**', '!**/social/**']
},
js: {
src: 'dist/*.min.js'
},
css: {
src: 'dist/*.min.css'
},
},
// replace original filenames with their revisioned coungterparts
// only changes in index.html & our minified css are necessary
usemin: {
html: ['dist/index.html', 'dist/last-minute.html', 'dist/feedback.html'],
css: ['dist/*.min.*.css']
},
// apply lossless image compression
// does also copy the images over to the `distributable` folder
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'img/',
src: ['**/*.{png,jpg,jpeg,gif}'],
dest: 'dist/img'
}]
}
},
// apply "lossless" svg optimization
// does also copy the svg´s over to the `distributable` folder
svgmin: {
options: {
plugins: [{
removeViewBox: false
}, {
removeUselessStrokeAndFill: false
}, {
convertPathData: {
straightCurves: false
}
}]
},
dist: {
files: [{
expand: true,
cwd: 'img/',
src: ['**/*.svg'],
dest: 'dist/img'
}]
}
}
});
// Load Grunt tasks automatically
require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });
// Default task(s).
// ORDER IS IMPORTANT
grunt.registerTask('default', [
// clean the distributabel folder
'clean:dist',
// concatenate js/css files & copy them over to the dist folder
// must be done before uglify & cssmin
'concat',
// minify the concatenated js files in the dist folder
'uglify',
// parse the concatenated css files and add vendor-prefixed CSS properties
'autoprefixer',
// minify the concatenated css files in the dist folder
'cssmin',
// copy over the static assets like the robots.txt
// static means here, that they won't be changed from some automated process
'copy:main',
// losslessy optimize images & copy them to the dist folder
'imagemin',
// losslessy optimize svgs & copy them to the dist folder
'svgmin',
// revision all the assets in the dist folder (must be done after all assets are copied)
'filerev',
// exchange all the in file references with the revisioned counterparts (must be done after the filerev task)
'usemin',
// minify the html contents, must be done after the usemin task,
// because it relies on comments in the HTML source
'htmlmin',
// housekeeping; remove unecessary artifacts that were generated during the process
'clean:afterMin'
]);
grunt.registerTask('deploy', [
'clean:site',
'copy:dist'
]);
};