我运行了两个Webpack开发服务器实例,但是热重装无法正常工作。 将更改应用于代码时,我会看到以下消息:
[WDS]热模块更换已启用。
[WDS]应用已更新。重新编译...
[WDS]应用程序热更新...
但是浏览器不会自动刷新。
我认为主机/我的自定义域有问题。
我在www.dev.mydomain.com:5000上运行该应用程序。
devServer.js
const _ = require('lodash');
const WebpackDevServer = require("webpack-dev-server")
const webpack = require("webpack")
const config = require("./webpack.dev.config")
const path = require('path');
const firstCompiler = webpack(config);
const secondCompiler = webpack(config);
const getPublicPath = ({ port }) => 'http://www.dev.mydomain.com:' + port + '/';
const options = {
hot: true,
host: '0.0.0.0',
headers: {
"Access-Control-Allow-Origin": "*"
},
disableHostCheck: true,
proxy: [{
context: ["/admin", "/api", "/accounts"],
target: "http://www.dev.mydomain.co"
}],
};
WebpackDevServer.addDevServerEntrypoints(config, options);
const firstApp = new WebpackDevServer(firstCompiler, _.assign({},options, {
historyApiFallback: {
index: getPublicPath({ port: '3000' }) + 'first_index.html',
},
}));
const secondApp = new WebpackDevServer(secondCompiler, _.assign({},options, {
historyApiFallback: {
index: getPublicPath({ port: '5000' }) + 'second_index.html',
},
}));
firstApp.listen(3000, function() {
});
secondApp.listen(5000, function() {})
webpack.config.js
entry: {
firstApp: ['webpack-dev-server/client?http://www.dev.mydomain.com:3000' ,"./scripts/firstApp.js"],
secondApp : ['webpack-dev-server/client?http://www.dev.mydomain.com:5000', "./scripts/secondApp.js"],
},