-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
58 lines (46 loc) · 1.48 KB
/
gulpfile.babel.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
'use strict';
import config from './gulp.config';
import gulp from 'gulp';
import plumber from 'gulp-plumber';
import connect from 'gulp-connect';
import htmlmin from 'gulp-htmlmin';
import postcss from 'gulp-postcss';
import precss from 'precss';
import cssnano from 'cssnano';
import rucksack from 'rucksack-css';
import postcssPresetEnv from 'postcss-preset-env';
import postcssCustomSelectors from 'postcss-custom-selectors';
import postcssCustomProperties from 'postcss-custom-properties';
const processors = [precss(), postcssPresetEnv(), rucksack(), postcssCustomSelectors(), postcssCustomProperties(), cssnano()];
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
// task css
gulp.task('css', () => {
return gulp
.src(`${config.src.css}/*.css`)
.pipe(plumber())
.pipe(postcss(processors))
.on('error', handleError)
.pipe(gulp.dest(config.public.css))
.pipe(connect.reload());
});
// task htmlmin
gulp.task('htmlmin', () => {
return gulp
.src(`${config.src.html}/*.html`)
.pipe(plumber())
.pipe(htmlmin({ collapseWhitespace: true, removeComments: true }))
.on('error', handleError)
.pipe(gulp.dest(config.public.html));
});
// default task
gulp.task('default', () => {
// create local server
connect.server(config.connect);
// watch all css files
gulp.watch(`${config.src.css}/**/*.css`, gulp.series('css'));
// watch all css files
gulp.watch(`${config.src.html}/**/*.html`, gulp.series('htmlmin'));
});