-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
32 lines (28 loc) · 1.08 KB
/
index.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
const webpack = require("webpack");
const webpackMiddleware = require("webpack-dev-middleware");
const webpackHotMiddleware = require("webpack-hot-middleware");
const reloader = require('./lib/reloader');
const createWatcher = require('./lib/FileWatcher');
/**
* Creates a webpack compiler, plus associated dev and hot reload middleware.
*
* @param {webpack.Configuration} webpackConfig
*/
exports.createMiddleware = function createMiddleware(webpackConfig) {
const webpackCompiler = webpack(webpackConfig);
const devMiddleware = webpackMiddleware(webpackCompiler, {
serverSideRender: true,
index: false,
publicPath: webpackConfig.output.publicPath,
headers: (req, res, _context) => {
const origin = req.headers['origin'];
if (!origin) return;
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('X-Derby-Webpack', 1);
}
});
const hotReloadMiddleware = webpackHotMiddleware(webpackCompiler);
return { devMiddleware, hotReloadMiddleware, webpackCompiler };
};
exports.reloader = reloader;
exports.createWatcher = createWatcher;