Gruntfile.js
4.39 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
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
/**
* 1 :: Combine and uglify all JavaScript sources into 1 minified file.
* Start with (external) libraries that are really needed (dependencies).
*/
uglify: {
build: {
files: {
'js/app.min.js': ['js/libs/*.js', 'js/app.js']
}
}
},
/**
* 2 :: Process SASS (SCSS) files and compile their CSS version.
*/
sass: {
options: {
// app.scss loads components from foundation.
// Without this include, grunt would not know where to get them from.
includePaths: ['bower_components/foundation/scss']
},
dist: {
options: {
// We will minify our final combined CSS file anyway.
outputStyle: 'normal'
},
files: {
'css/app.css': 'scss/app.scss',
}
}
},
/**
* 3 :: Combine different CSS files into 1 file.
* Start with (external) CSS (libs) that are really needed.
*/
concat_css: {
options: {
// Task-specific options go here.
},
all: {
src: ['css/**/*.css', '!css/style*css'],
dest: 'css/style-unprefixed.css'
},
},
/**
* 4 :: If there is CSS3 that needs browser-specific prefixes,
* this library will add these (create the different variants).
* On the contrary, if the original CSS contains prefixes that are no
* longer marked as needed, it will remove them (e.g. border-radius).
*/
autoprefixer: {
global: {
files : {
'css/style.css': 'css/style-unprefixed.css'
}
}
},
/**
* 5 :: Minify the prefixed CSS file to preserve bandwidth.
*/
cssmin: {
build: {
src: 'css/style.css',
dest: 'css/style.min.css'
}
},
/**
* 6 :: Combine all svg files and create one mapped svg sprite we can include.
*/
svgstore: {
options: {
prefix: "shape-",
cleanup: false,
svg: {
style: "display: none;"
}
},
default: {
files: {
'assets/svg-defs.svg': ['svg/*.svg']
}
}
},
/** @TODO: PNG fallback for IE */
/**
* 7 :: Run PHP through parser to create static HTML
* (needed to include our critical css automatically).
* This is not possible on most dynamic sites.
* Search for alternative or extract critical CSS manually...
*/
php2html: {
default: {
options: {
// relative links should be renamed from .php to .html
processLinks: true,
htmlhint: false,
},
files: [
{expand: false, cwd: './', src: ['*.php'], dest: './', ext: '.html' }
]
}
},
/**
* 8 :: Extract critical CSS for a defined "above the fold" area.
* If more finetuning is desired: alternative with more options
* or external tool is needed.
*/
penthouse: {
extract : {
outfile : './css/critical.css',
css : './css/style.css',
url : 'http://kevin.demo/cssoptim/index.html',
width : 1024,
height : 980
},
},
/**
* 9 :: Automatically include CSS that is defined inline in the HTML file.
* Include the ?__inline=true query parameter on assets that need to be
* inlined. Example:
* <link href="css/critical.css?__inline=true" rel="stylesheet" />
*/
inline: {
dist: {
options:{
cssmin: true
},
src: ['index.html'],
}
},
/**
* X :: Watch files for changes and act on them (recompile etc...).
*/
watch: {
options: {
livereload: true,
},
grunt: {
files: ['Gruntfile.js']
},
css: {
files: ['scss/**/*.scss', 'css/libs/*.css'],
tasks: ['sass', 'concat_css', 'autoprefixer', 'cssmin']
},
scripts: {
files: ['js/**/*.js', '!js/**/*.min.js'],
tasks: ['uglify']
},
svg: {
files: 'svg/**/*.svg',
tasks: ['svgstore']
}
}
});
// Load necessairy grunt tasks based on npm modules.
require("load-grunt-tasks")(grunt);
grunt.registerTask('critical', ['uglify', 'svgstore', 'sass', 'concat_css', 'autoprefixer', 'php2html', 'penthouse' ,'inline', 'cssmin']);
grunt.registerTask('build', ['uglify', 'svgstore', 'sass', 'concat_css', 'autoprefixer', 'cssmin']);
grunt.registerTask('default', ['build','watch']);
}