【发布时间】:2017-05-11 13:29:02
【问题描述】:
我正在使用 webpack-dev-server 进行热模块更换。它工作得很好,但每隔几秒就会在控制台中显示此错误:GET http://mysite:8080/__webpack_hmr 404 (Not Found)。
这是我的 webpack.config.js:
var webpack = require('webpack'),
hostname = 'mysite',
port = 8080;
module.exports = {
entry: [
'babel-polyfill',
'./src/js/main.js',
'./dev/requireCss.js',
'webpack/hot/dev-server',
// I'm assuming the fault lies in the following line, but I can't figure out what's wrong
'webpack-hot-middleware/client?path=http://'+hostname+':'+port+'/__webpack_hmr'
],
output: {
path: __dirname + '/webpack',
filename: "bundle.js",
publicPath: 'http://'+hostname+':'+port+'/'
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loaders: ['react-hot', 'babel-loader?presets[]=react&presets[]=es2015']
} // removed some loaders for brevity
]
},
resolve: {
extensions: ['', '.json', '.js', '.jsx']
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
devtool: "source-map",
devServer: {
contentBase: __dirname + '/dev',
hot: true,
proxy: [{
path: /\/(?!__webpack_hmr).+/, // I get the same error if I change this to 'path: /\/.+/'
target: 'http://my-backend.localhost'
}]
}
};
这个想法是开发服务器应该将除/ 和__webpack_hmr 之外的所有请求转发到我的后端(my-backend.localhost)。这适用于除__webpack_hmr 之外的所有内容。
我可以在我的 conf 中进行更改以使错误消失吗?
【问题讨论】:
标签: webpack webpack-dev-server