我正在从节点服务一个Webpack捆绑包,并尝试使用‘webpack-热-中间件’进行热重载。
Webpack捆绑包使用了一个'var‘libraryTarget,并公开了一个导出所有模块的文件:
Webpack配置示例:
const config = {
entry: './lib/src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
library: "myLib",
libraryTarget: 'var',
},
...webpack-热-中间件文档设置说明如下:
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公开的全局变量在这一点上是未定义的。
谢谢你的建议。
发布于 2021-04-30 04:59:17
您与:entry: ['./lib/src/index.js', 'webpack-hot-middleware/client']关系密切。
您需要将其更改为:
entry: {
main: ['./lib/src/index.js', 'webpack-hot-middleware/client']
}entry的值必须是字符串或对象。当他们说“在入口数组中添加‘webpack-热-中间件/客户端’‘时,the webpack-hot-middleware/client对此有点困惑。”我遇到了与您相同的问题,只有在查看了webpack entry documentation和一些实现示例后才能弄清楚。
https://stackoverflow.com/questions/66322997
复制相似问题