-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
66 lines (55 loc) · 1.54 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
const { parallel, series, src, dest, watch } = require('gulp');
const webpack = require('webpack');
const webpackstream = require('webpack-stream');
const del = require('del');
const browsersync = require('browser-sync').create();
const webpackConfigDev = require('./webpack.config.dev');
const jsonServer = require('gulp-json-srv');
const db = jsonServer.create();
const destPath = 'build';
function scripts() {
return src('src/')
.pipe(webpackstream(webpackConfigDev, webpack))
.pipe(dest(destPath))
.pipe(browsersync.stream());
}
function html() {
return src('public/*.html')
.pipe(dest(destPath))
.pipe(browsersync.stream());
}
function startDB() {
return src('./db.json')
.pipe(db.pipe())
.pipe(browsersync.stream());
}
function browserSync(done) {
browsersync.init({
server: {
baseDir: `${destPath}`,
},
port: 8080,
});
done();
}
function reload(done) {
browsersync.reload();
done();
}
function watchFiles() {
watch(['src/**/*.{scss,js,svg,png,jpg,gif}', 'db.json'], reload);
}
function clean() {
return del([destPath]);
}
exports.start = series(
clean,
parallel(startDB, browserSync, scripts, html),
watchFiles,
);
// There should also be a real build step for production using
// process.env.NODE_ENV === 'production' that trims a lot of React
// base code and using a minification process using a webpack production
// config with production mode and a minification plugin like terser-webpack-plugin.
// exports.build = series(clean, parallel(scripts, html));
exports.default = scripts;