具有多个条目的HtmlWebpackPlugin会忽略注入时的其他块

时间:2019-01-21 10:22:42

标签: javascript webpack html-webpack-plugin

在webpack配置中具有多个入口点,例如:

 entry: {
    home: './resources/assets/scripts/sections/home/home.bundle.js',
    calc: './resources/assets/scripts/sections/calc/calc.bundle.js',
    (...)
  }

以及splitChunks的优化,例如:

  optimization: {
        splitChunks: {
            chunks: "all",
            cacheGroups: {
                vendors: {
                    test: /[\\/]node_modules[\\/]/,
                    priority: -10
                },
                default: {
                    minChunks: 2,
                    priority: -20,
                    reuseExistingChunk: true
                }
            }
        }
    },

并使用HtmlWebPackPlugin,例如:

new HtmlWebPackPlugin({
    template: "./resources/views/pages/app/sub-pages/home.blade.template.php",
    filename: "../../resources/views/pages/app/sub-pages/home.blade.php",
    inject: true,
    chunks: ['home'] // <--- what should be going here?
}),
new HtmlWebPackPlugin({
    template: "./resources/views/pages/app/sub-pages/calc.blade.template.php",
    filename: "../../resources/views/pages/app/sub-pages/calc.blade.php",
    inject: true,
    chunks: ['calc'] // <--- what should be going here?
}),

HtmlWebPackPlugin仅向home注入1 home.blade.php块,向calc文件注入1 calc.blade.php块,而忽略其他文件。

但是... webpack会生成更多文件,例如: vendors~home~calc.js vendors~calc.js vendors~home.js (...)

我尝试过的是在htmlWebPackPlugin配置中省略任何chunks,但是随后所有文件都被注入,因此vendors~calshome.blade.php中,等等...这是错误的

如何配置插件以仅使用其中包含homecalc的文件(块)?

0 个答案:

没有答案