-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
gulpfile.js
59 lines (53 loc) · 1.45 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
// Load plugins
const browsersync = require('browser-sync').create();
const gulp = require('gulp');
const autoprefixer = require('autoprefixer');
const postcssImport = require("postcss-import")
const cssnano = require('cssnano');
const postcss = require('gulp-postcss');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const sourcemaps = require('gulp-sourcemaps');
const cleanCss = require('gulp-clean-css');
// BrowserSync
function browserSync(done) {
browsersync.init({
server: {
baseDir: './',
},
port: 3000,
});
done();
}
// BrowserSync Reload
function browserSyncReload(done) {
browsersync.reload();
done();
}
// CSS task
function css() {
return gulp
.src('./src/**/[^_]*.css')
.pipe(plumber())
.pipe(postcss([autoprefixer(), postcssImport()]))
.pipe(gulp.dest('css/'))
.pipe(postcss([cssnano()]))
.pipe(rename({ suffix: '.min' }))
.pipe(cleanCss({ compatibility: 'ie8' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('css/'))
.pipe(browsersync.stream());
}
// Watch files
function watchFiles() {
gulp.watch('./src/**/*', css);
gulp.watch('*.html', browserSyncReload);
}
// define complex tasks
const build = gulp.series(css);
const watch = gulp.parallel(watchFiles, browserSync);
// export tasks
exports.css = css;
exports.build = build;
exports.watch = watch;
exports.default = build;