umijs / mako

An extremely fast, production-grade web bundler based on Rust.
https://makojs.dev
MIT License
1.75k stars 65 forks source link

[RFC] ignore plug is too simple #1300

Open stormslowly opened 3 months ago

stormslowly commented 3 months ago

https://github.com/umijs/mako/blob/45f9278b76b5c820a7ab98a41ab52ddf041be991/crates/mako/src/plugins/ignore.rs#L14-L24

simple_ignore 的实现太 simple 了。 一旦在 resolve 阶段 ignore 了这个模块,那么在后面的阶段都“看不见“它,module graph 也没有它。 我们无法管理一个不存在的模块;所有后继的 concatenate 优化中也无法判定他是一个 inner 还是 external,也无法统计 ignore 模块如何被引用过,因此也无法得出如何 interop 它。

不能有看不见的 module ,那么就造一个虚拟的来替代它

举例如果配置 ignores: ['worker_thread']

  1. 利用 resolve_as 字段将 worker_thread 转换成 virtual模块 virtual::worker_thread?ignored
  2. loader 将 virtual::worker_thread?ignored 加载为
    // module id virual::worker_thtread?ignored
    module.exports = require('worker_thread')
  3. 在 before_resolve 中处理该模块,没有任何依赖。

后继的处理 virtual::worker_thread?ignored 就作为原来的 worker_thread 的"替身"

stormslowly commented 2 months ago

需要考虑 minifish 场景下, 引入 virtual 文件,导致中间产物不同。