Webpack 4静态资产未使用HtmlWebpackPlugin重新加载
我正在使用npm和HtmlWebpackPlugin配置一个简单的webpack 4设置,以生成index.html,这一切都很好,只是它仅在运行我的产品构建时生成文件,并且对模板的更改不会自动反映在浏览器中 这是我的webpack.config.js文件Webpack 4静态资产未使用HtmlWebpackPlugin重新加载,webpack,html-webpack-plugin,webpack-4,Webpack,Html Webpack Plugin,Webpack 4,我正在使用npm和HtmlWebpackPlugin配置一个简单的webpack 4设置,以生成index.html,这一切都很好,只是它仅在运行我的产品构建时生成文件,并且对模板的更改不会自动反映在浏览器中 这是我的webpack.config.js文件 const path = require('path'); const webpack = require('webpack'); const CopyWebpackPlugin = require('copy-webpack-plugin'
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// Static data
const castingteamData = require('./castingteam.json');
module.exports = {
entry: './src/app/app.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
},
module: {
rules: [
..................................omitted loaders
]
},
plugins: [
new HtmlWebpackPlugin({
data: castingteamData,
template: 'src/app/index.html'
})
],
devServer: {
contentBase: './dist',
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
};
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new CopyWebpackPlugin([
{
from: 'src/assets/img/',
to: 'assets/img/',
toType: 'dir'
}
]),
new CopyWebpackPlugin([
{
from: 'src/assets/fonts',
to: 'assets/fonts',
toType: 'dir'
}
]),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
在package.json中,我有两个脚本:
"scripts": {
"build": "cross-env NODE_ENV=production webpack --progress --hide-
modules",
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot"
}
正如我所说,index.html是在运行npm运行构建时正确生成的,但npm运行开发没有乐趣。看起来这应该是一个简单的修复,但我找不到它 网页包开发服务器似乎没有像js和css文件那样跟踪html文件。Javascript和css的更改会立即反映在浏览器中,但在html模板更改后,我需要刷新浏览器。是这样的还是可以更方便地设置?