gpt4 book ai didi

webpack-hot-middleware 不是热替换

转载 作者:行者123 更新时间:2023-12-01 10:35:36 31 4
gpt4 key购买 nike

这是我的服务器代码:

if (process.env.NODE_ENV === 'development') {
// Enable logger (morgan)
app.use(morgan('dev'));

// Disable views cache
app.set('view cache', false);

var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');

var webpackConfig = require('../client/webpack.config');
var compiler = webpack(webpackConfig);

app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: webpackConfig.output.publicPath }));
app.use(webpackHotMiddleware(compiler));

}

这是我的 webpack.config:
module.exports = {
entry: {
main: [
'webpack-hot-middleware/client',
'./client/src/main'
]
},
output: {
path: path.join(__dirname, 'client/build'),
filename: 'bundle.js',
publicPath: '/build/'
},
plugins: [
new AureliaWebpackPlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{ test: /\.js$/, loader: 'babel', exclude: /node_modules/, query: {stage: 0} },
{ test: /\.css?$/, loader: 'style!css' },
{ test: /\.html$/, loader: 'raw' },
{ test: /\.(png|gif|jpg)$/, loader: 'url-loader?limit=8192' },
{ test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff2' },
{ test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader' }
]
}
};

每次更改源文件时,webpack 重建都没有问题。但是,浏览器中没有热替换/重新加载......我错过了什么吗?我以为我非常严格地遵循了说明。

提前致谢。

最佳答案

当我在 webpack-hot-middleware 中添加一些参数以启用 HMR,并在入口中向 webpack-hot-middleware/client 查询参数时,我的问题成功解决,如下所示:

//#server.js  add parameters to Enables HMR
app
.use(webpackHotMiddleware(compiler, {
'log': false,
'path': '/__webpack_hmr',
'heartbeat': 10 * 1000
}))


//# webpack.config.js:
entry: {
main: [
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true',
'./client/src/main'
]

关于webpack-hot-middleware 不是热替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36121535/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com