-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.mjs
52 lines (45 loc) · 1.3 KB
/
gulpfile.mjs
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
// jshint node:true
import gulp from 'gulp';
import gulpSass from 'gulp-sass';
import sass from 'sass';
import autoprefixer from 'gulp-autoprefixer';
import sourcemaps from 'gulp-sourcemaps';
import cleanCSS from 'gulp-clean-css';
import browserSync from 'browser-sync';
const bs = browserSync.create();
const sassCompiler = gulpSass(sass);
const sassSources = "./scss/**/*.scss";
const cssDest = "./css";
const mapDest = "./maps";
const htmlSources = ["./pages/**/*.html", "./partials/**/*.html"];
// Compiles Sass, autoprefixes, minifies, and creates sourcemaps
function css() {
return gulp.src(sassSources)
.pipe(sourcemaps.init())
.pipe(sassCompiler().on('error', sassCompiler.logError))
.pipe(autoprefixer())
.pipe(cleanCSS({
level: 1
}))
.pipe(sourcemaps.write(mapDest))
.pipe(gulp.dest(cssDest))
.pipe(bs.stream());
}
// Build files once
gulp.task('build', css);
// Run BrowserSync after HTML changes
/* gulp.task("sync", function () {
// Pipe nothing
return gulp.src("!./")
.pipe(bs.stream());
}); */
// Watch and build files on change
gulp.task('watch', function () {
css();
bs.init({
server: "./"
});
//gulp.watch(htmlSources, ['sync']);
gulp.watch(htmlSources).on('change', bs.reload);
gulp.watch(sassSources, gulp.series(css));
});