forked from udacity/frontend-nanodegree-mobile-portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
183 lines (166 loc) · 5.17 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
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
//--Javascript--//
////run jsHint for code quality check:
jshint: {
myFiles: ['app/**/*.js']
},
uglify: {
dist: {
options: {
sourceMap: true
},
files: [{
expand: true,
cwd: 'app/',
src: ['**/*.js'],
dest: 'build/'
}]
}
},
//--Styling--//
////output converted scss as css to build folder:
sass: {
dist: {
options: {
style: 'expanded'
},
files: [{
expand: true,
cwd: 'app/',
src: ['**/*.scss'],
dest: 'build/',
ext: '.css'
}]
}
},
////css optimizations:
postcss: {
options: {
map: true,
processors: [
require('autoprefixer')({browsers: ['last 3 versions']}), // add/remove browser prefixes
require('css-mqpacker')({autoprefixer: false, zindex: false}), // combine identical media queries (skipping autoprefixer as included above for addition as well as removal, skipping zindex in case JS relies on z-index values)
require('cssnano')() //minify and other optimizations
]
},
dist: {
src: 'build/**/*.css'
}
},
//--HTML--//
////output minified HTML to build folder
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: [{
expand: true,
cwd: 'app/',
src: ['**/*.html'],
dest: 'build/'
}]
}
},
//--Images--//
////output losslessly compressed images to build folder
imagemin: {
dist: {
files: [{
expand: true,
cwd: 'app/',
src: ['**/*.{png,jpg,gif}'],
dest: 'build/'
}]
}
},
//--Server--//
////run a local server to test development
connect: {
build: {
options: {
port: 9001,
keepalive: true,
base: 'build'
}
}
},
//--Watch--//
watch: {
scripts: {
files: ['app/**/*.js'],
tasks: ['jshint', 'uglify'],
options: {
spawn: false,
livereload: true
},
},
css: {
files: ['app/**/*.scss'],
tasks: ['sass','postcss'],
options: {
spawn: false,
livereload: true
}
},
html: {
files: ['app/**/*.html'],
tasks: ['htmlmin','critical'],
options: {
spawn: false,
livereload: true
}
}
},
//--Clean--//
////tasks for removing css and images before rebuilding - simple way to make sure files deleted from 'app' also get removed from 'build'.
////for now only covers images and css (and maps) but may expand to cover more in future
clean: {
images: ['build/**/*.{png,jpg,gif}'],
css: ['build/**/*.{css,css.map}']
},
//--Critical--//
////Running this on the build file to inline critical css
critical: {
dist: {
options: {
inline: true,
base: './build',
minify: true,
width: 1300,
height: 900
},
src: 'build/index.html',
dest: 'build/index.html'
}
}
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-htmlmin')
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-critical');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', [
'clean:images',
'clean:css',
'jshint',
'uglify',
'sass',
'postcss',
'htmlmin',
'critical',
'imagemin',
'connect:build',
]);
};