簡體   English   中英

具有單一入口點的 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: ['./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的值必須是字符串或 object。 當他們說“將'webpack-hot-middleware/client'添加到條目數組中”時the webpack-hot-middleware/client對此有點困惑。 我遇到了與您相同的問題,並且只有在查看webpack 條目文檔並查看一些實施示例后才能弄清楚。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM