-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
217 lines (210 loc) · 7.18 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
module.exports = function( grunt ) {
'use strict';
// Add timing graph after each task
require( 'time-grunt' )( grunt );
// load all task listed and speed up build process
require( 'jit-grunt' )( grunt );
// Project configuration
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
meta: {
day: '<%= grunt.template.today("dd-mm-yyyy") %>',
hour: '<%= grunt.template.today("HH:MM") %>',
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - <%= meta.day %> <%= meta.hour %> */\n',
dev: {
assets: 'app',
css: '<%= meta.dev.assets %>/styles',
js: '<%= meta.dev.assets %>/scripts',
img: '<%= meta.dev.assets %>/images',
fonts: '<%= meta.dev.assets %>/fonts'
},
prod: {
assets: 'build',
css: '<%= meta.prod.assets %>/styles',
js: '<%= meta.prod.assets %>/scripts',
img: '<%= meta.prod.assets %>/images',
fonts: '<%= meta.prod.assets %>/fonts'
}
},
eslint: {
options: {
configFile: 'conf/.eslintrc'
},
target: ['<%= meta.dev.js %>/main.js']
},
// Clean files assets in folders
clean: {
assets: [ '<%= meta.prod.assets %>' ]
},
// Copy files and folders
copy: {
font: {
expand: true, // Enable dynamic expansion
cwd: '<%= meta.dev.fonts %>/', // Src matches are relative to this path
src: [ '*.{eot,svg,ttf,otf,woff,woff2}' ], // Actual patterns to match
dest: '<%= meta.prod.fonts %>/' // Destination path prefix
},
js: {
expand: true,
cwd: '<%= meta.dev.js %>/',
src: [ '**/*.js' ],
dest: '<%= meta.prod.js %>/'
},
images: {
expand: true,
cwd: '<%= meta.dev.img %>/',
src: [ '**/*.*' ],
dest: '<%= meta.prod.img %>/'
}
},
// Grunt PostCSS task
postcss: {
options: {
map: true,
processors: [
require('postcss-import'),
require('postcss-custom-properties'),
require('postcss-calc'),
require('postcss-custom-media'),
require('postcss-media-minmax'),
require('postcss-custom-selectors'),
require('postcss-color-hex-alpha'),
require('postcss-color-function'),
require('postcss-selector-matches'),
require('postcss-selector-not'),
require('postcss-nested'),
require("css-mqpacker")(),
require('autoprefixer')({
browsers: ['> 1%', 'IE 9']
}),
require('postcss-neat')({
neatMaxWidth: '100%'
})
]
},
lint: {
options: {
map: false,
processors: [
require( 'stylelint' )({
configFile: "conf/.stylelintrc"
})
]
},
src: [ "<%= meta.dev.css %>/**/*.css" ]
},
docs: {
options: {
processors: [
require('mdcss')
]
},
src: [ "<%= meta.dev.css %>/**/*.css" ]
},
dev: {
src: '<%= meta.dev.css %>/main.css',
dest: '<%= meta.prod.css %>/main.css'
},
prod: {
options: {
map: false
},
src: '<%= meta.dev.css %>/main.css',
dest: '<%= meta.prod.css %>/main.css'
}
},
// Minify PNG, JPEG and GIF images
imagemin: {
images: {
files: [ {
expand: true,
cwd: '<%= meta.dev.img %>/',
src: [ '**/*.{png,jpg,gif,svg,ico}' ],
dest: '<%= meta.prod.img %>/'
} ]
}
},
// Minify CSS
csswring: {
options : {
map: false,
removeAllComments: true
},
prod: {
src: '<%= postcss.prod.dest %>',
dest: '<%= meta.prod.css %>/main.css'
}
},
// Minify JS
uglify: {
options: {
banner: "<%= meta.banner %>"
},
prod: {
expand: true,
cwd: '<%= meta.dev.js %>/',
src: [ '**/*.js' ],
dest: '<%= meta.prod.js %>/'
}
},
// Process throught phatomJS to create the critical css File
critical: {
prod: {
options: {
// Inline the generated critical-path CSS
// - true generates HTML
// - false generates CSS
inline: false,
width: 1280,
height: 768,
minify: true,
// Extract inlined styles from referenced stylesheets
extract: true,
// ignore some css rules
ignore: ['font-face',/some-regexp/],
},
src: 'http://getbootstrap.com/',
dest: '<%= meta.prod.css %>/critical.css'
}
},
// Watch and livereload with help of grunt-newer
watch: {
options: {
livereload: 6325
},
js: {
files: [ '<%= meta.dev.js %>/main.js', '<%= meta.dev.js %>/modules/*.js' ],
tasks: [ 'newer:copy:js' ]
},
image: {
files: '<%= meta.dev.img %>/**/*.{png,jpg,gif,svg,ico}',
tasks: [ 'newer:copy:images' ]
},
css: {
files: ['<%= meta.dev.css %>/main.css', '<%= meta.dev.css %>/**/*.css'],
tasks: [ 'postcss:dev' ]
},
template: {
files: 'path/to/template/**/*.*'
}
},
// Run grunt tasks concurrently
concurrent: {
base: [ "postcss:dev",
"copy"
],
prod: [ "postcss:prod",
"imagemin",
"copy:font"
],
compress: [ "uglify", "csswring" ],
lint: [ "postcss:lint", "eslint" ]
}
} );
// Default task
grunt.registerTask( "default", [ "concurrent:base" ]);
// Lint task
grunt.registerTask( "lint", [ "concurrent:lint" ] );
// Prod task
grunt.registerTask( "prod", [ "clean", "concurrent:prod", "concurrent:compress", "critical" ]);
};