Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dll webpack plugin #3360

Merged
merged 8 commits into from
Aug 5, 2020
Merged

Feat/dll webpack plugin #3360

merged 8 commits into from
Aug 5, 2020

Conversation

LanceZhu
Copy link
Collaborator

No description provided.

@chenbin92
Copy link
Collaborator

用户需要怎么配置,使用 DLL 之后提升的数据是怎样的 ?

@chenbin92 chenbin92 requested review from chenbin92 and ClarkXia July 27, 2020 01:24
@LanceZhu

This comment has been minimized.

@LanceZhu

This comment has been minimized.

packages/plugin-react-app/src/index.js Outdated Show resolved Hide resolved
packages/plugin-react-app/src/index.js Outdated Show resolved Hide resolved
packages/plugin-react-app/src/index.js Outdated Show resolved Hide resolved
packages/plugin-react-app/src/index.js Outdated Show resolved Hide resolved
@ClarkXia
Copy link
Collaborator

通过配置 dllEntry 的方式来设置,相对比较繁琐,建议给到一个默认策略,比如所有 dependencies 默认都构建到 dll 中,配置具体 dllEntry 的方式可以作为补充方式,方案上可以借鉴下 https://github.com/ice-lab/ice-scripts/pull/48/files 的思路

@chenbin92
Copy link
Collaborator

chenbin92 commented Aug 2, 2020

  1. 解决下冲突
  2. 文档补充
  3. 上面无用的回复可以删除了

@LanceZhu LanceZhu force-pushed the feat/dll-webpack-plugin branch from 5b3575f to 91f3f7f Compare August 3, 2020 02:18
@LanceZhu
Copy link
Collaborator Author

LanceZhu commented Aug 3, 2020

DllPlugin 优化效果

示例及依赖选择

选取 hello-world,fusion-design-pro-ts,fusion-design-lite-ts 为实验对象,对于占比较大的产物通过 DllPlugin 预先构建,测量再次构建时,构建时间变化。

  • hello-world:总体积(396K)中 react-dom (134.29K)、 core-js (112.15K)所占比例较大。
  • fusion-design-pro-ts:总体积(2.7M)中 bizcharts (672.51K)、 react-dom (134.29K)、 core-js (112.7K)、 moment (61.64K)所占比例较大。
  • fusion-design-lite-ts:总体积(776K)中 react-dom (134.29K)、 core-js (112.44K)、 moment (61.64K)占比较大。

实验

对每个示例均做3次实验,得到下表:

DllPlugin 实验记录

构建速度记录表中 加粗斜体 数字为3次实验的平均值。
使用平均值对比构建速度变化,得到 使用 DllPlugin 后构建速度变化 图为:

DllPlugin 速度变化

由图看出 DllPlugin 对于三个示例构建速度均有提升。

提升比率分别为:

DllPlugin 构建速度提升比率

结论

由图中数据可以得出 DllPlugin 对于构建速度有明显提升,平均可提升 20%。且项目越大,速度提升效果越明显。

packages/plugin-react-app/src/userConfig/dll.js Outdated Show resolved Hide resolved
chainConfig.resolve.modules.add(path.resolve(rootDir, 'node_modules'));

return new Promise((resolve, reject) => {
webpack(chainConfig.toConfig(), err => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在现有 icejs 的架构下支持多任务构建,没必要在单独引入 webpack 进行构建

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前有尝试使用多任务构建,但构建时 DllReferencePlugin 报错找不到 DllPlugin 的产物。可能之前使用有问题,我再试下。

@LanceZhu
Copy link
Collaborator Author

LanceZhu commented Aug 4, 2020

使用 Webpack 多任务构建时。构建业务代码时 DllReferencePlugin 无法加载 DllPlugin 产物即 vendor.manifest.json
好像是 Webpack 的问题,文档上说 multiCompiler顺序执行的。

Multiple configurations will not be run in parallel. Each configuration is only processed after the previous one has finished processing. To process them in parallel, you can use a third-party solution like parallel-webpack.

复现

目录结构:

├── index.js
└── webpack.multi.js

index.js

// index.js
console.log('index');

webpack.multi.js

// webpack.multi.js
const path = require('path');

module.exports = [{
  mode: 'production',
  entry: './index.js',
  output: {
    path: path.join(__dirname),
    filename: 'build.js'
  }
}, {
  mode: 'production',
  entry: './build.js',
  output: {
    path: path.join(__dirname),
    filename: 'dist.js'
  }
 }];

执行

$ webpack-cli --config webpack.multi.js

报错
image

@chenbin92 chenbin92 merged commit 0bcbd66 into release-next Aug 5, 2020
@delete-merged-branch delete-merged-branch bot deleted the feat/dll-webpack-plugin branch August 5, 2020 10:04
@chenbin92 chenbin92 mentioned this pull request Aug 6, 2020
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants