-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdev-server.js
68 lines (58 loc) · 1.69 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
/*eslint-env node*/
/**
* Require Browsersync along with webpack and middleware for it
*/
var browserSync = require("browser-sync");
var webpack = require("webpack");
var webpackDevMiddleware = require("webpack-dev-middleware");
var webpackHotMiddleware = require("webpack-hot-middleware");
var historyApiFallback = require("connect-history-api-fallback");
/**
* Require ./webpack.config.js and make a bundler from it
*/
var webpackConfig = require("./webpack.config");
/**
* dev-specific modifications
*/
webpackConfig.entry = [].concat([
"webpack/hot/dev-server",
"webpack-hot-middleware/client"
], webpackConfig.entry);
webpackConfig.devtool = "#eval-source-map";
webpackConfig.plugins = [].concat(webpackConfig.plugins, [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.LoaderOptionsPlugin({
debug: true
})
]);
var bundler = webpack(webpackConfig);
/**
* Run Browsersync and use middleware for Hot Module Replacement
*/
browserSync({
https: true,
notify: false,
server: {
baseDir: "app",
middleware: [
historyApiFallback(),
webpackDevMiddleware(bundler, {
// IMPORTANT: dev middleware can’t access config, so we should
// provide publicPath by ourselves
publicPath: webpackConfig.output.publicPath,
// pretty colored output
stats: {
colors: true,
chunkModules: false,
modules: false
}
// for other settings see
// http://webpack.github.io/docs/webpack-dev-middleware.html
}),
// bundler should be the same as above
webpackHotMiddleware(bundler)
]
}
});