单独的捆绑包构成动态导入的节点模块

我在webpack配置中有以下配置用于拆分块。完美地创建了两个捆绑软件供应商(在初始文件中导入的节点模块)和common(在懒加载的组件中导入的节点模块)

splitChunks: {
        name: true,cacheGroups: {
          default: false,vendors: false,vendor: {
            test: /[\\/]node_modules[\\/]/,name: "vendors",chunks: "initial"
          },common: {
            test: /[\\/]node_modules[\\/]/,name: "common",minChunks: 2,chunks: "async",priority: 10,reuseExistingChunk: true,enforce: true
          }
        }
      },

问题-,但是有些节点模块不希望包含在任何捆绑软件中。以上两个包或主要包都不能单独创建。

import('lodash')应该创建一个lodash.chunk.js。

import('underscore')应该创建一个underscore.chunk.js。

我可以以为魔术评论吗? / * webpack忽略:true * /

wly1zwss 回答:单独的捆绑包构成动态导入的节点模块

这里,您的lodash将基于当前的splitchunks添加到公共块中 组态。要将其作为单独的块加载,请将splitchunks配置更改为

var vendorCheck = function vendorCheck(module) {
  var request = module.userRequest;
  // Specify the packages in the condition that need not be present in vendor chunk
  // Here I am excluding the package lodash from vendor chunk
  return request && request.indexOf('node_modules') >= 0 && request.indexOf('node_modules/lodash') === -1
};

var lodashCheck = function lodashCheck(module) {
  var request = module.userRequest;
  return request && request.indexOf('node_modules/lodash') >= 0
}

cacheGroups: {
    default: false,'lodash': {
      name: 'lodash',chunks: 'all',minChunks: 1,test: lodashCheck
    },vendor: {
      name: 'vendor',test: vendorCheck
    },common: {
        test: vendorCheck,name: "common",minChunks: 2,chunks: "async",priority: 10,reuseExistingChunk: true,enforce: true
    }
}
本文链接:https://www.f2er.com/3160711.html

大家都在问