使用了html-webpack-plugin之后怎么使用DevServer实时刷新啊???
第一步:修改webpack-dev-server 的配置 或者通过命令来修改webpack-dev-server --hotOnly
。
devServer: { hot: true },
第二步:引入插件: html-webpack-plugin、clean-webpack-plugin(每次都重新清除一次dist(目标)文件目录); 引入webpack
const HtmlWebpackPlugin = require('html-webpack-plugin'); const CleanWebpackPlugin = require('clean-webpack-plugin'); const webpack = require('webpack');
第三步:使用webpack内置插件HMR
plugins: [ new CleanWebpackPlugin(['dist']), new HtmlWebpackPlugin({ title: 'Hot Module Replacement' }), new webpack.HotModuleReplacementPlugin() ],