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: optimize runtime when build #5082

Merged
merged 19 commits into from
Jan 6, 2022
Merged

Conversation

ClarkXia
Copy link
Collaborator

Resolve #5048

@ClarkXia ClarkXia changed the base branch from release-next to master December 28, 2021 12:19
@ClarkXia ClarkXia changed the base branch from master to release-next December 28, 2021 12:20
@codecov-commenter
Copy link

codecov-commenter commented Dec 29, 2021

Codecov Report

Merging #5082 (c288ac0) into release/2.5.0 (5924850) will increase coverage by 1.37%.
The diff coverage is 78.06%.

Impacted file tree graph

@@                Coverage Diff                @@
##           release/2.5.0    #5082      +/-   ##
=================================================
+ Coverage          28.81%   30.18%   +1.37%     
=================================================
  Files                196      197       +1     
  Lines               5067     5211     +144     
  Branches            1222     1271      +49     
=================================================
+ Hits                1460     1573     +113     
- Misses              3325     3352      +27     
- Partials             282      286       +4     
Impacted Files Coverage Δ
packages/plugin-react-app/src/config.js 100.00% <ø> (ø)
packages/vite-service/src/build.ts 0.00% <0.00%> (ø)
packages/vite-service/src/start.ts 0.00% <0.00%> (ø)
packages/build-mpa-config/src/index.ts 51.66% <61.53%> (+0.64%) ⬆️
packages/build-app-helpers/src/analyzeRuntime.ts 79.79% <79.79%> (ø)
packages/plugin-mpa/src/index.ts 84.54% <90.90%> (+0.67%) ⬆️
packages/build-app-helpers/src/index.ts 100.00% <100.00%> (ø)
packages/plugin-react-app/src/setBuild.js 100.00% <100.00%> (ø)

@ClarkXia ClarkXia changed the base branch from release-next to release/2.5.0 December 29, 2021 11:18

const prodConfig = wp2vite(context);
if (!configArr.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这是什么情况?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

目前 vite 模式下的配置均是基于 webpack 配置转化的,如果没有 webpack 配置的情况下,是不需要执行构建的,start 阶段已有这个判断,修正了下 build 模式下的逻辑

mode = 'vite';
} else if (webpackConfig) {
alias = webpackConfig?.[0].chainConfig?.toConfig?.()?.resolve?.alias;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

这种代码看着有点头疼的,未来还是得想办法统一掉。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

嗯 这里本质原因是 vite 和 webpack 配置的 alias 内容是不一致的,vite 下是通过 {find: string, replacement: string}[] 的方式,而 webpack 是 k-v

packages/plugin-mpa/src/index.ts Outdated Show resolved Hide resolved
@@ -13,19 +13,30 @@ function generatePageFiles(api: IPluginAPI, options: IGeneratorOptions): IGenera
}

const { context: { userConfig } } = api;
generator.generateRunAppFile(userConfig);
// 在分析运行时依赖的场景下,不能直接执行 generator
// 需要在分析完成并执行 disableRuntimePlugins 逻辑后,再执行生成
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个时序控制太难受了,执行顺序有点乱,有没有可能把 analyzeRuntime 前置掉?

Copy link
Collaborator Author

@ClarkXia ClarkXia Jan 4, 2022

Choose a reason for hiding this comment

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

因为 analyzeRuntime 依赖完整的 webpack 配置,所有分析的行为必须发生在 before.${command}.load 阶段,分析完成后才能进行 generator

packages/plugin-mpa/src/index.ts Outdated Show resolved Hide resolved
packages/build-mpa-config/src/generate/BaseGenerator.ts Outdated Show resolved Hide resolved
packages/build-app-helpers/src/analyzeRuntime.ts Outdated Show resolved Hide resolved
packages/build-app-helpers/src/analyzeRuntime.ts Outdated Show resolved Hide resolved
@ClarkXia ClarkXia requested a review from imsobear January 4, 2022 07:49
@ClarkXia ClarkXia merged commit 7973ef1 into release/2.5.0 Jan 6, 2022
@ClarkXia ClarkXia deleted the feat-optimize-build branch January 6, 2022 07:55
@ClarkXia ClarkXia mentioned this pull request Jan 11, 2022
8 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.

4 participants