-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
84 lines (68 loc) · 2.15 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
83
84
// gulp
const gulp = require('gulp');
const clean = require('gulp-clean');
const mustache = require('gulp-mustache');
const browserSync = require('browser-sync').create('bsServer');
// vars
const dev = require('./gulpfile.dev').functions;
const prod = require('./gulpfile.prod').functions;
const justMoveFileTypes = 'jpg,png,gif,svg,php,pdf,ico,mp3';
const nodeFiles = [
// {
// src: './node_modules/photoswipe/src/css/default-skin/default-skin.png',
// dest: './dist/assets/img/photoswipe'
// }
]
// shared tasks
function compileTemplates() {
return gulp
.src('./src/**/*.html')
.pipe(mustache())
.pipe(gulp.dest('./dist/'))
.pipe(browserSync.stream());
}
function moveFiles() {
return gulp
.src('./src/**/*.{' + justMoveFileTypes + '}')
.pipe(gulp.dest('./dist/'))
.pipe(browserSync.stream());
}
function getNodeModuleAssets(cb) {
for (let i = 0; i < nodeFiles.length; i++) {
const file = nodeFiles[i];
const src = file.src;
const dest = file.dest;
gulp
.src(src)
.pipe(gulp.dest(dest))
}
cb();
}
function deleteDist() {
return gulp.src('./dist', { read: false, allowEmpty: true }).pipe(clean());
}
// browsersync
function bsServe() {
browserSync.init({
server: {
baseDir: './dist',
index: '/index.html',
},
open: 'external',
// open: false,
notify: false,
ghostMode: false,
});
gulp.watch('./src/**/*.{' + justMoveFileTypes + '}', moveFiles);
gulp.watch('./src/**/*.mustache', compileTemplates);
gulp.watch('./src/**/*.html', compileTemplates);
gulp.watch('./src/**/*.scss', dev.compileScss);
gulp.watch('./src/**/*.js', dev.compileWebpack);
gulp.watch('./src/**/*.ts', dev.compileWebpack);
gulp.watch('./src/**/*.json', dev.compileWebpack);
}
// register tasks
const devCompile = gulp.series(deleteDist, gulp.parallel(compileTemplates, dev.compileScss, dev.compileWebpack, getNodeModuleAssets, moveFiles,));
exports.compile = devCompile;
exports.start = gulp.series(devCompile, bsServe);
exports.prod = gulp.series(deleteDist, gulp.parallel(compileTemplates, prod.compileScss, prod.compileWebpack, getNodeModuleAssets, moveFiles));