-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
83 lines (69 loc) · 1.89 KB
/
gulpfile.babel.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
'use strict';
// import
import gulp from 'gulp';
import watch from 'gulp-watch';
import pug from 'gulp-pug';
import open from 'gulp-open';
import readConfig from 'read-config';
import webpack from 'webpack';
import webpackDevServer from 'webpack-dev-server';
import webpackConfig from './webpack.config.babel';
import CONFIG from './config.json';
// const
const SRC = `./${CONFIG.dev.src}`;
const HTDOCS = `./${CONFIG.dev.dist}`;
const BASE_PATH = '';
const DEST = `${HTDOCS}${BASE_PATH}`;
const ASSETS = CONFIG.dev.assets;
// html
gulp.task('pug', () => {
const { meta } = readConfig('./config.json');
const locals = meta;
locals.basePath = BASE_PATH;
locals.env = process.env.NODE_ENV;
locals.datetime = (new Date().getTime());
return gulp.src(`${SRC}/pug/**/[!_]*.pug`)
.pipe(pug({
locals: locals,
pretty: true,
basedir: `${SRC}/pug`}))
.pipe(gulp.dest(`${DEST}`));
});
gulp.task('html', ['pug']);
// copy
gulp.task('copy', function () {
return gulp
.src(`${SRC}/static/**`)
.pipe(gulp.dest(`${DEST}/`));
});
gulp.task('watch', () => {
watch([
`${SRC}/pug/**/*.pug`,
'./config.json'
], () => {
gulp.start('pug')
//TODO: reload on dev server
})
watch([`${SRC}/direct/*`], () => {
gulp.start('copy')
})
});
gulp.task('open', function(){
gulp.src('.')
.pipe(open({uri:'http://localhost:' + CONFIG.dev.port}));
});
gulp.task('webpack-dev-server', (callback) => {
const compiler = webpack(webpackConfig);
new webpackDevServer(compiler, {
contentBase: CONFIG.dev.dist,
publicPath: webpackConfig.output.publicPath,
hot: true,
}).listen(CONFIG.dev.port, '0.0.0.0', (err) => {
if (err) {
console.log(err);
}
console.log('Listening at localhost:' + CONFIG.dev.port);
});
});
gulp.task('default', ['webpack-dev-server', 'html', 'watch', 'copy', 'open']);
gulp.task('build', ['html', 'copy']);