-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
82 lines (66 loc) · 1.58 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
77
78
79
80
81
82
// Initialize mpdules
const { src, dest, watch, series, 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 uglify = require('gulp-uglify');
const browserSync = require('browser-sync');
// File path variables
const files = {
scssPath: 'app/scss/**/*.scss',
jsPath: 'app/js/**/*.js',
htmlPath: 'index.html'
}
// BrowserSync task
function browserSyncTask(done){
browserSync.init({
server: {
baseDir: '.'
}
});
done();
}
// Sass task
function scssTask(){
return src(files.scssPath)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(postcss([ autoprefixer(), cssnano() ]))
.pipe(sourcemaps.write('.'))
.pipe(dest('dist'))
.pipe( browserSync.stream()
);
}
// JS task
function jsTask() {
return src(files.jsPath)
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(dest('dist'))
.pipe( browserSync.stream()
);
}
// Cachebusting task
const cbString = new Date().getTime();
function cacheBustTask() {
return src(['index.html'])
.pipe(replace(/cb=\d+/g, 'cb=' + cbString))
.pipe(dest('.')
);
}
// Watch task
function watchTask(){
watch([files.scssPath, files.jsPath, files.htmlPath],
parallel(browserSyncTask, scssTask, jsTask)
);
}
// Default task
exports.default = series(
parallel(browserSyncTask, scssTask, jsTask),
cacheBustTask,
watchTask
);