-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev-server.js
33 lines (27 loc) · 1010 Bytes
/
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
/* eslint-disable no-console */
const WebpackDevServer = require('webpack-dev-server');
const webpack = require('webpack');
const WriteFilePlugin = require('write-file-webpack-plugin');
const path = require('path');
const config = require('./webpack.config');
// add HMR entry points
Object.keys(config.entry).forEach((entryName) => {
config.entry[entryName] = [
(`webpack-dev-server/client?http://localhost:${process.env.PORT}`),
'webpack/hot/dev-server',
].concat(config.entry[entryName]);
});
// add dev specific plugins
config.plugins = [new webpack.HotModuleReplacementPlugin()].concat(config.plugins || []);
config.plugins = [new WriteFilePlugin({
test: /^(?!.*(hot)).*/, // exclude hot-update files
})].concat(config.plugins || []);
const compiler = webpack(config);
const options = {
hot: true,
contentBase: path.resolve(__dirname, 'build'),
open: true,
openPage: 'bookmarks.html',
};
const server = new WebpackDevServer(compiler, options);
server.listen(process.env.PORT);