forked from alibaba/arthas-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
63 lines (56 loc) · 1.78 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
require('@babel/register')();
const gulp = require('gulp');
const gutil = require('gulp-util');
const webpack = require('webpack');
const opn = require('opn');
const WebpackDevServer = require('webpack-dev-server');
const siteConfig = require('./site_config/site').default;
const webpackConfig = require('./webpack.config.js');
const port = siteConfig.port || 8080;
function webpack_server(cb) {
// body omitted
// modify some webpack config options
const myConfig = Object.create(webpackConfig);
myConfig.plugins.push(new webpack.SourceMapDevToolPlugin({}));
// Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig), {
publicPath: `http://127.0.0.1:${port}/build/`,
stats: {
colors: true,
},
}).listen(port, '127.0.0.1', (err) => {
if (err) throw new gutil.PluginError('webpack-dev-server', err);
opn(`http://127.0.0.1:${port}/`);
});
cb();
}
function webpack_build(callback) {
// modify some webpack config options
const myConfig = Object.create(webpackConfig);
myConfig.output.publicPath = `${siteConfig.rootPath}/build/`;
myConfig.plugins = myConfig.plugins.concat(
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.optimize.UglifyJsPlugin()
);
// run webpack
webpack(myConfig, (err, stats) => {
if (err) throw new gutil.PluginError('webpack:build', err);
gutil.log(
'[webpack:build]',
stats.toString({
colors: true,
})
);
callback();
});
}
const webpackserver = gulp.series(webpack_server);
// The development server (the recommended option for development)
gulp.task('default', webpackserver);
// Production build
gulp.task('build', gulp.series(webpack_build));