We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
为了支持 MPA 场景,需要支持多 entry,配置方式类似:
{ entry: { pageA: './src/pages/A.tsx', pageB: './src/pages/B.tsx' } }
以及在 MPA 的场景下,提取 shared chunk 是常见需求,需要 Code Splitting 能支持对 initial chunk 做提取,在 webpack 中的配置类似:
{ common: { chunks: 'initial', name: 'common', minChunks: 2, }, }
主要解决 4 个问题:
以下是每个问题具体的解法。
目前看应该在 map 数据生成的时候改为根据 chunk graph 查找依赖的 chunks(包含间接依赖)即可,关键代码位置:
mako/crates/mako/src/generate_chunks.rs
Line 72 in 98b38ef
此前留出了 OptimizeAllowChunks::Entry 的口子但没实现,需要做如下改动:
OptimizeAllowChunks::Entry
ChunkType::Entry
ChunkDependency
codeSplitting
cacheGroups
有两个思路,但为了降低接入框架的成本,okam 层始终还是会暴露类似 html-webpack-plugin 的配置项:
entryHtmlTpl: { filename: string; template: string; templateParameters: string; chunks: string[] }
应该必须要引入 namespace 的概念了,因为在有 shared chunk 的情况下,shared chunk 通常是先于 entry chunk 加载的,它会把自己包含的模块先放入 namespace 的 map 中,类似:
(self.webpackChunk_example_mpa = self.webpackChunk_example_mpa || []).push([ [503], { 881: function (ln, k, ne) { ... } }, ]);
Mako 目前的 chunksIdToUrlMap 是套在 runtime 的闭包里的,需要有类似 webpack namespace 的机制暴露出来,改动点:
chunksIdToUrlMap
self.mako_modules_pkg_name
mako/crates/mako/templates/app_runtime.stpl
Lines 270 to 290 in 6ff7123
mako/crates/mako/src/chunk_pot/str_impl.rs
Line 124 in 1cd1e92
mako/crates/mako/src/optimize_chunk.rs
Line 401 in a93c482
Line 109 in c9121c9
mako/crates/mako/src/config.rs
Line 275 in 98bfb6b
Line 274 in 98bfb6b
mako/crates/mako/src/generate.rs
Lines 220 to 221 in 895f571
entrypoints
entrypoints: { name: string; chunks: string[] }
mako/crates/mako/src/stats.rs
Line 136 in 6ec55aa
The text was updated successfully, but these errors were encountered:
runtime 支持 shared chunk 和 entry chunk 的模块合并
xianglin 那边需要这个功能了
Sorry, something went wrong.
PR 已提,快去催他 👀
主要功能已完成,可供框架接入,RFC 关闭
Successfully merging a pull request may close this issue.
功能描述
为了支持 MPA 场景,需要支持多 entry,配置方式类似:
以及在 MPA 的场景下,提取 shared chunk 是常见需求,需要 Code Splitting 能支持对 initial chunk 做提取,在 webpack 中的配置类似:
问题分析
主要解决 4 个问题:
以下是每个问题具体的解法。
解决思路
runtime map 数据区分 entry
目前看应该在 map 数据生成的时候改为根据 chunk graph 查找依赖的 chunks(包含间接依赖)即可,关键代码位置:
mako/crates/mako/src/generate_chunks.rs
Line 72 in 98b38ef
Code Splitting 支持 entry chunk 的公共模块提取
此前留出了
OptimizeAllowChunks::Entry
的口子但没实现,需要做如下改动:OptimizeAllowChunks::Entry
,生成对应的 optimize_info 对象ChunkType::Entry
的 chunk,并与原 chunk 建立依赖关系ChunkDependency
记录该依赖关系是异步的还是同步的codeSplitting
的配置项,允许接入框架自定义 Mako 的 optimizeGroups(类似 webpack 的cacheGroups
)HTML 生成时处理 chunks 的依赖关系
有两个思路,但为了降低接入框架的成本,okam 层始终还是会暴露类似 html-webpack-plugin 的配置项:
entryHtmlTpl: { filename: string; template: string; templateParameters: string; chunks: string[] }
,然后在 generate 阶段根据该配置生成最终的 HTML 文件,插入 script 时需要根据 chunks 中的 chunk 查找到上游 sync chunk 依赖作为前置 script 引入,okam 直接透传配置(不选的原因:上层框架比如 Smallfish 对 HTML 生成的自定义程度很高,Mako 只提供静态配置项很难支持)runtime 支持 shared chunk 和 entry chunk 的模块合并
应该必须要引入 namespace 的概念了,因为在有 shared chunk 的情况下,shared chunk 通常是先于 entry chunk 加载的,它会把自己包含的模块先放入 namespace 的 map 中,类似:
Mako 目前的
chunksIdToUrlMap
是套在 runtime 的闭包里的,需要有类似 webpack namespace 的机制暴露出来,改动点:任务拆分
self.mako_modules_pkg_name
,在 entry 初始化时自动注册 namespace 中的已有模块,以支持 shared chunk 先于 entry 加载的场景mako/crates/mako/templates/app_runtime.stpl
Lines 270 to 290 in 6ff7123
mako/crates/mako/src/chunk_pot/str_impl.rs
Line 124 in 1cd1e92
mako/crates/mako/src/generate_chunks.rs
Line 72 in 98b38ef
OptimizeAllowChunks::Entry
的 optimize_info 对象生成 entry chunkmako/crates/mako/src/optimize_chunk.rs
Line 401 in a93c482
mako/crates/mako/src/generate_chunks.rs
Line 109 in c9121c9
mako/crates/mako/src/config.rs
Line 275 in 98bfb6b
HTML 生成能力讨论后发现纯配置无法满足内部框架的诉求,所以方案改为 Mako 层产出 stats.json,框架根据 stats.json 生成 HTML,这样可以高度自定义[ ] 新增配置项entryHtmlTpl: { filename: string; template: string; templateParameters: string; chunks: string[] }
关键位置:
pub hmr_host: String,
mako/crates/mako/src/config.rs
Line 274 in 98bfb6b
[ ] 在 generate 阶段根据上面的配置项和 Chunk Graph 生成对应 HTML 产物关键位置:
let t_generate_chunks = t_generate_chunks.elapsed();
mako/crates/mako/src/generate.rs
Lines 220 to 221 in 895f571
entrypoints
字段描述 entry 和所依赖的 chunk 文件 的关系,参考 Webpack 的结构,仅提供需要的字段数量entrypoints: { name: string; chunks: string[] }
mako/crates/mako/src/stats.rs
Line 136 in 6ec55aa
The text was updated successfully, but these errors were encountered: