-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
76 lines (65 loc) · 1.8 KB
/
gulpfile.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
const gulp = require('gulp');
const rename = require('gulp-rename');
const server = require('browser-sync').create();
const postcss = require('gulp-postcss');
const atImport = require("postcss-import")
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const cleanCSS = require('gulp-clean-css');
const sass = require('gulp-sass');
const del = require('del');
del.sync('./dist');
function reload(done) {
server.reload();
done();
}
function serve(done) {
server.init({
server: './dist',
host: '0.0.0.0',
port: 8888,
cors: true,
});
done();
}
gulp.task('html', () => gulp.src('./src/*.html').pipe(gulp.dest('./dist')));
gulp.task('scss', () => {
const plugins = [
atImport(),
autoprefixer({
browsers: ['> 5%', 'ie >= 9', 'ff >= 28', 'Chrome >= 21'],
cascade: false
}),
// cssnano()
];
return gulp.src(['./src/scss/*.scss', '!_*.scss'])
.pipe(sass().on('error', sass.logError))
.pipe(postcss(plugins))
.pipe(gulp.dest('./dist'))
.pipe(rename({ suffix: ".min" }))
.pipe(cleanCSS({
advanced: false,
keepBreaks: true,
keepSpecialComments: '*',
level: { 1: { specialComments: false }}
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('webserver', gulp.series(serve));
gulp.task('watch:html', () => gulp.watch('./src/*.html', gulp.series('html', reload)));
gulp.task('watch:scss', () => gulp.watch('./src/scss/**/*.scss', gulp.series('scss', reload)));
gulp.task('watch', gulp.parallel([
'watch:html',
'watch:scss'
]));
gulp.task('dev',
gulp.series([
'html',
'scss',
gulp.parallel([
'watch',
'webserver'
])
])
);
gulp.task('default', gulp.parallel('dev'));