forked from unpkg/unpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateDevServer.js
54 lines (45 loc) · 1.34 KB
/
createDevServer.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
const express = require('express');
const morgan = require('morgan');
const WebpackDevServer = require('webpack-dev-server');
const devErrorHandler = require('errorhandler');
const devAssets = require('./middleware/devAssets');
const createDevCompiler = require('./createDevCompiler');
const createRouter = require('./createRouter');
function createDevServer(publicDir, webpackConfig, devOrigin) {
const compiler = createDevCompiler(
webpackConfig,
`webpack-dev-server/client?${devOrigin}`
);
const server = new WebpackDevServer(compiler, {
// webpack-dev-middleware options
publicPath: webpackConfig.output.publicPath,
quiet: false,
noInfo: false,
stats: {
// https://webpack.js.org/configuration/stats/
assets: true,
colors: true,
version: true,
hash: true,
timings: true,
chunks: false
},
// webpack-dev-server options
contentBase: false,
disableHostCheck: true,
before(app) {
// This runs before webpack-dev-middleware
app.disable('x-powered-by');
app.use(morgan('dev'));
}
});
// This runs after webpack-dev-middleware
server.use(devErrorHandler());
if (publicDir) {
server.use(express.static(publicDir));
}
server.use(devAssets(compiler));
server.use(createRouter());
return server;
}
module.exports = createDevServer;