0
我一直在尝试多次配置webpack。每次我开始这个过程时,自动重新加载都可以正常工作,直到我为web-dev-server启用--hot,那么对html的任何更改都没有影响,没有错误,没有任何内容,只是登录终端已经存在更改以及浏览器控制台上的日志,无需更新。热重载工作正常的CSS和JS,我理解HTML不支持HMR但至少希望自动刷新继续工作......HMR启用时如何使自动重新加载工作
我的配置如下:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
const webpack = require('webpack');
module.exports = {
entry: './src/js/index.js',
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new HtmlWebpackPlugin({
title: 'Hello world',
template: 'src/views/index.html',
alwaysWriteToDisk: true
}),
new HtmlWebpackHarddiskPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
],
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
hot: true,
inline: true,
open: true,
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader',
]
}
]
}
};
我的包脚本。 json
"scripts": {
"dev": "webpack-dev-server --config webpack.config.js",
"prod": "cross-env NODE_ENV=production webpack -p --config webpack.config.js"
},
还没有测试过这个,但尝试[reload-html-webpack-plugin](https://github.com/andrewcoelho/reload-html-webpack-plugin) – andykenward
谢谢,我已经尝试了上面的许多其他解决方案,但每次自动重新加载开始工作时,我失去CSS上的HMR(假设还有JS,还没有测试过)。我想有自动重新加载在HTML和CSS和JS的HMR。 – jjaulimsing