4

有没有办法将依赖模块中动态导入创建的块文件作为主应用程序中的块文件包含在内。

这是我正在尝试的 -

我有两个 npm 模块,比如 M1、M2。

M2 使用 import() 运算符动态导入 M1。在捆绑 M2 时,我使用 webpackChunkName 创建 vendor~M1.js

M2.js

...

import(/* webpackChunkName: "M1" */ 'M1/index')
.then(){}

然后有一个静态导入 M2 的反应应用程序 A1。

A1.js

import index from 'M2'

...

在捆绑 A1 时,我使用 splitChunks 为 M2 创建 M2bundle.js

webpack.config.js 看起来像这样 -

        splitChunks: {
          cacheGroups: {
            default: false,
            commons: {
              test: /[\\/]node_modules[\\/]/,
              name: 'M2bundle',
              chunks: 'all',
              minChunks: 1,
            },
          },
        },

此输出为 A1.js 创建 main.js,为 M2 模块创建 M2bundle.js,但它不包括 node_module/M2 目录中的 vendor~M1.js。

webpack 配置中有没有办法实现这一点?

感谢帮助!

4

0 回答 0