首页 > 解决方案 > Webpack 优化问题

问题描述

迁移到 webpack 4.16.0 后,我遇到了问题。

我有 2 个这样定义的条目

entry: {
  app: ['./src/app.js'],
  index: ['./src/index.js']
},

和两个html页面

new HtmlWebpackPlugin({
  template: './index.html',
  filename: './index.html',
  inject: 'head',
  title: 'Content Stream',
  chunks: ['index']
}),
new HtmlWebpackPlugin({
  template: './app.html',
  filename: './app.html',
  title: 'Content Stream',
  chunks: ['vendor', 'app']
})

使用webpack.optimization(工作正常)

optimization: {
    splitChunks: {
      cacheGroups: {
        commons: {
          test: /[\\/]node_modules[\\/]/,
          name: 'vendor',
          chunks: 'all'
        }
      }
    }
  },

在我添加块index之前,不会执行页面上捆绑的代码。vendor但我在那里不需要它。

我收到index块内容,但看起来和谐模块初始化运行部分已移至vendor

那么如何处理呢?

标签: javascriptoptimizationwebpack

解决方案


推荐阅读