This repository has been archived by the owner on Aug 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
dev-server.js
executable file
·78 lines (69 loc) · 2.27 KB
/
dev-server.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
const _ = require('lodash');
const webpackDevServer = require("webpack-dev-server");
const webpack = require('webpack');
const pathJoin = require('path').join;
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const commonConfig = require('./common.config.js');
const getAssets = require('./assets');
const join = _.partial(pathJoin, __dirname);
const opts = {
host: 'localhost',
port: 8080,
publicPath: '/',
outputPath: '/',
filename: '/bundle.js',
// watchOptions: undefined,
// watchDelay: undefined,
historyApiFallback: true,
hot: true,
https: false,
errorDetails: true,
contentBase: __dirname,
stats: {
errorDetails: true,
cached: false,
cachedAssets: false,
colors: true,
},
inline: true
};
const protocol = opts.https ? "https" : "http";
function logServerInfo() {
const slug = opts.inline ? '/' : '/webpack-dev-server/';
console.log(protocol + ":https://" + opts.host + ":" + opts.port + slug);
console.log("webpack result is served from " + opts.publicPath);
if (typeof opts.contentBase === "object") {
console.log("requests are proxied to " + opts.contentBase.target);
} else {
console.log("content is served from " + opts.contentBase);
}
if (opts.historyApiFallback) {
console.log("404s will fallback to %s", opts.historyApiFallback.index
|| "/index.html");
}
}
const nodeModules = [ join('node_modules') ];
getAssets().then(assets => {
const config = _.defaults({
output: { path: '/', filename: '/bundle.js' },
devServer: { hot: true },
// devtool: 'eval-source-map',
entry: {
main: [
'webpack-dev-server/client?'+ protocol +':https://'+ opts.host +':'
+ opts.port,
'webpack/hot/only-dev-server',
'./src/dev-main.js',
]
}
}, commonConfig);
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new ProgressBarPlugin({ callback: logServerInfo })
// new webpack.WatchIgnorePlugin(/* pathArray or regExpr */),
);
new webpackDevServer(webpack(config), opts)
.listen(opts.port, opts.host, err => { if (err) throw err });
}).catch(err => console.log(err))