突然,webpack-dev-server不再在源更改时重新加载。 HRM已正确加载,但是更改源代码不会再触发热重新加载。以前它工作正常。

我发现有很多人在Stackoverflow中问同样的问题。他们每个人都有不同的解决方案,尽管我尝试过,但没有一个对我有用。因此,这不是重复的问题,因为我尝试了已经提供的解决方案,但是没有一个对我有用。

我尝试清理软件包并重新安装所有软件包
我试图使用不同的路径进入webpack配置的“入口”

webpack.config.js

var path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')

const webpack = require('webpack')

module.exports = {
  mode: 'development',
  entry: './src/index.tsx',
  resolve: {
      extensions: [".ts", ".tsx", ".js"]
    },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'app.bundle.js'
  },

    plugins: [
          new HtmlWebpackPlugin({
            title: "test app",
            filename: "./index.html",
            template: "src/index.html",
            inject: "body",
          }),
          new CopyWebpackPlugin([{ from: 'assets', to: 'assets'}]),
          new webpack.DefinePlugin({
              VERSION:     JSON.stringify(process.env.npm_package_version),
      }),
      new webpack.HotModuleReplacementPlugin({

      }),
    ],

  devServer: {
    contentBase: path.join(__dirname, 'dist'),
compress: true,
host: "localhost",
port: 9000,
hot: true,
disableHostCheck: true,
  },
  module: {
    rules: [
    { test: /\.(tsx)?$/,
      loader: "ts-loader",
        exclude: path.join(__dirname, 'node_modules'),
    },
    {test: /\.css$/, use: ['style-loader',{loader:'css-loader',     options:{}}]}
    ],
  },
  node: {
fs: 'empty'
  }

};


我希望HRM像往常一样工作。

最佳答案

我突然又开始工作,没有任何明显的原因。我没有修改任何配置文件或源文件,现在,运行开发服务器将在源代码更改后正确地热重载。

因此,我可以得出结论,这不是项目的任何配置文件中的错误,但可能与开发服务器的实现本身或操作系统未通过文件的更改有关吗?

10-08 00:15