-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev-tools.js
40 lines (33 loc) · 1.11 KB
/
dev-tools.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
"use strict";
/**
* webpack hot
*/
var webpack = require("webpack");
var WebpackDevServer = require("webpack-dev-server");
var webpackConfig = require("./webpack.config.dev.js");
var assign = require("object-assign");
var cors = require("express-cors");
function start(publicUrl, expressApp) {
// Run the webpack dev server
var compiler = webpack(webpackConfig);
var devConfig = assign({}, webpackConfig.devServer, {
contentBase: publicUrl,
publicPath: webpackConfig.output.publicPath
});
new WebpackDevServer(compiler, devConfig)
.listen(webpackConfig.devServer.port, "localhost", function (err) {
if (err) {
console.log(err);
}
else {
console.log("Webpack server listening on port", webpackConfig.devServer.port);
}
});
// add cors for hot reload server
expressApp.use(cors({allowedOrigins: ["localhost" + ":" + webpackConfig.devServer.port]}));
// use webpack dev server for serving js files
expressApp.use("/js", function (req, res) {
res.redirect( webpackConfig.output.publicPath.slice(0, -1) + req.path);
});
}
module.exports.start = start;