具有单一入口点的 webpack-hot-middleware 设置

webpack-hot-middleware setup with single entry point

我正在从节点提供 Webpack 包并尝试使用 'webpack-hot-middleware' 进行热重载。

Webpack 包使用 'var' libraryTarget 并公开导出所有模块的单个文件:

Webpack 配置示例:

const config = {
    entry: './lib/src/index.js',
    output: {
      path: path.resolve(__dirname, 'dist'),
      publicPath: '/',
      library: "myLib",
      libraryTarget: 'var',
    },
    ...

webpack-hot-middleware 文档设置说明说:

2) Add 'webpack-hot-middleware/client' into the entry array. This connects to the server to receive notifications when the bundle rebuilds and then updates your client bundle accordingly.

问题是 - 由于我没有入口数组,我如何/如何使用我当前的单个入口点配置来设置它?

我尝试过的:

将 'entry' 值从字符串转换为数组,如下所示:

entry: ['./lib/src/index.js', 'webpack-hot-middleware/client']

然而,从 index.js 公开的全局变量在那时变得未定义。

感谢您的任何建议。

您与: entry: ['./lib/src/index.js', 'webpack-hot-middleware/client'].

您需要将其更改为:

entry: {
    main: ['./lib/src/index.js', 'webpack-hot-middleware/client']
}

entry 的值必须是字符串或对象。当他们说“将 'webpack-hot-middleware/client' 添加到条目数组中”时,the webpack-hot-middleware/client 对此有点困惑。我遇到了与您遇到的相同问题,并且只有在查看 webpack entry documentation 并查看一些实施示例后才能弄清楚。