我将webpack 4更新到了webpack 5,更新后一切都可以工作,除了浏览器无法更新(即时重载),有谁能告诉我原因吗?这是我的配置。
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const autoprefixer = require('autoprefixer');
module.exports = (env, argv) => {
const { mode = 'development' } = argv;
const isProd = mode === 'production';
const isDev = mode === 'development';
const getStyleLoaders = () => {
return [isProd ? MiniCssExtractPlugin.loader : 'style-loader'];
};
return {
context: path.resolve(__dirname, 'src'),
mode: isProd ? 'production' : isDev && 'development',
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: isDev ? 'script/script.js' : 'script/bundle-[hash:8].js',
publicPath: '/',
},
resolve: {
extensions: ['.js'],
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
publicPath: '/',
open: true,
watchContentBase: true,
port: 8080,
},
devtool: isProd ? false : 'source-map',
};
};