This repository was archived by the owner on Feb 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
51 lines (42 loc) · 1.43 KB
/
gulpfile.js
File metadata and controls
51 lines (42 loc) · 1.43 KB
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
'use strict';
const gulp = require('gulp');
const gutil = require('gulp-util');
const webpack = require('webpack');
gulp.task('build', callback => {
const path = require('path');
const replace = require('gulp-replace');
const config = require('./webpack.config.prod');
require('rimraf').sync('dist/');
gulp.src(['img/**/*', 'fonts/**/*', 'robots.txt', 'sitemap.xml', '404.html'], {'base': '.'})
.pipe(gulp.dest('dist/'));
webpack(config, (err, stats) => {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString());
gulp.src(['index.html'], {'base': '.'})
.pipe(replace(
'</head>',
`<link rel="stylesheet" href="${stats.hash}.index.bundle.css">\n</head>`
))
.pipe(replace('index.bundle.js', `${stats.hash}.index.bundle.js`))
.pipe(gulp.dest('dist/'))
.on('end', callback);
});
});
gulp.task('watch', callback => {
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config.dev');
new WebpackDevServer(webpack(config), {
historyApiFallback: true,
publicPath: '/build/'
}).listen(8080, 'localhost', err => {
if (err) {
throw new gutil.PluginError('webpack-dev-server', err);
}
// Server listening
gutil.log('[webpack-dev-server]', 'http://localhost:8080/webpack-dev-server/index.html');
// keep the server alive or continue?
// callback();
});
});