-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
55 lines (48 loc) · 1.35 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
import {join} from 'path';
import gulp from 'gulp';
import gutil, {PluginError} from 'gulp-util';
import {argv} from 'yargs';
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import config from './webpack.config';
var entryConfig = config;
var devEntry = [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/dev-server'
];
if(argv.dev) {
entryConfig.entry.push.apply(entryConfig.entry, devEntry);
entryConfig.devtool = 'inline-source-map';
}
const compiler = webpack(entryConfig);
const logger = (err, stats) => {
if(err) throw new PluginError('webpack-dev-server', err);
if(argv.dev) {
gutil.log('[webpack-dev-server]', 'http://localhost:3000/webpack-dev-server/');
} else {
gutil.log(stats.toString());
}
};
gulp.task('default', ['copy'], () => {
if(argv.dev) {
new WebpackDevServer(compiler, {
contentBase: join(process.cwd(), 'dist'),
publicPath: config.output.publicPath,
hot: true,
quiet: false,
noInfo: false,
watchDelay: 300,
headers: { 'X-Custom-Header': 'yes' },
stats: { colors: true }
}).listen(3000, 'localhost', logger);
} else {
compiler.run(logger);
}
});
gulp.task('copy', () => {
return gulp.src('./src/*.html')
.pipe(gulp.dest('./dist'))
});
gulp.task('watch', () => {
gulp.watch('./src/*.html', ['copy']);
});