-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
61 lines (54 loc) · 1.51 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
// Initialize modules
const { src, dest, series, watch, parallel } = require('gulp');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const concat = require('gulp-concat');
const postcss = require('gulp-postcss');
const replace = require('gulp-replace');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const terser = require('gulp-terser');
const babel = require('gulp-babel');
// File path variables
const files = {
scssPath: './assets/styles/sass/**/*.scss',
jsPath: './assets/js/**/*.js'
}
// Sass taks
function scssTask(){
return src(files.scssPath)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(postcss([ autoprefixer(), cssnano() ]))
.pipe(sourcemaps.write('.'))
.pipe(dest('dist/css'));
}
// JS taks
function jsTask(){
return src(files.jsPath)
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(concat('main.js'))
.pipe(terser())
.pipe(dest('dist/js'));
}
// Cachebusting task
const cbString = new Date().getTime();
function cacheBustTask(){
return src(['index.html'])
.pipe(replace(/cb=\d+/g, 'cb=' + cbString))
.pipe(dest('.'));
}
// Watch task
const watchTask = function() {
watch("./assets/styles/sass/**/*.scss", {usePolling : true}, series(scssTask));
watch("./assets/js/**/*.js", {usePolling : true}, series(jsTask));
};
// Default task
exports.default = series(
parallel(scssTask, jsTask),
cacheBustTask,
watchTask
);
exports.watch = watchTask;