-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulptasks.js
40 lines (40 loc) · 1.32 KB
/
gulptasks.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
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const pxtorem = require('postcss-pxtorem');
module.exports = (plugins, config) => {
/*是否是线上环境*/
let ispro = config.env === 'production' || process.env.NODE_ENV === 'production';
return {
scsss: (stream) => {
let postcsss = [
autoprefixer(config.autoprefixer),
pxtorem(config.pxtorem)
]
if (ispro) {
postcsss.push(cssnano());
}
stream = stream.pipe(plugins.sass().on('error', plugins.sass.logError));
stream = stream.pipe(plugins.postcss(postcsss));
return stream;
},
scripts: (stream) => {
stream = stream.pipe(plugins.babel(config.babel));
if (ispro) {
stream = stream.pipe(plugins.uglify())
}
return stream;
},
images: (stream) => {
if (ispro) {
// stream = stream.pipe(plugins.imagemin());
}
return stream;
},
htmls: (stream) => {
if (ispro) {
stream = stream.pipe(plugins.htmlmin({ collapseWhitespace: true, minifyCSS: true, minifyJS: true }));
}
return stream;
}
}
}