【Rolldown源码】二、了解Rolldown的目标

675 阅读2分钟

写给自己看的Rolldown代码解析,有问题可以讨论。

关于构建Rolldown的原由及路线图在链接中都有介绍

根据文章介绍,得知Rolldown的以下几个特点或目标

  • 尽可能与 Rollup 的 API 和插件接口保持一致,方便vite过渡到使用Rolldown
  • 想要解决Esbuild在输出上的问题,尤其是chunk分割限制的问题
  • 加快打包速度,使用native languages(rust)写bundler,避免生产构建中源码被不同工具重复解析、转化和序列化
  • chunk 分割逻辑可能与 Rollup 的不同
  • 范围上Rolldown 更类似于 Esbuild,带有内置的 CommonJS 支持、 node_modules解析并且将来还将支持 TypeScript / JSX、转换和压缩能力。
  • Rolldown 也可以直接作为独立的打包工具使用

下面是Rolldown的规划路线,未来可以对照的看功能实现

Milestone 1: Basic Bundling

  • Goal: to be able to use Rolldown instead of esbuild to perform dependency pre-bundling in Vite.
  • Key features needed:
    •  Basic code splitting for multiple entrypoints
    •  cjs / esm mixed bundling
    •  Basic plugin support

Milestone 2: Advanced Bundling

  • Goal: to be able to use Rolldown for production builds in Vite.
  • Key features needed:
    •  Treeshaking
    •  Basic CLI & config file support by @kazupon
    •  Source map @underfin
    •  Chunk hashing @hyf0
    •  Full Rollup plugin compatibility WIP by @hyf0 & @underfin Tracking issue
    •  Advanced chunk splitting
    •  Module Federation
    •  Built-in CSS bundling

Milestone 3: Transform Features

  • Goal: to be able to use Rolldown for all current esbuild usage in Vite.
  • These features will be relying on oxc which is developed in parallel to Rolldown. We want these integrated in Rolldown so we can reuse the same AST as much as possible.
  • Key features needed:
    •  Built-in Typescript / JSX transform (via oxc)
    •  Built-in minification (via oxc)
    •  Syntax lowering (via oxc)

Milestone 4: Deeper Vite Integration

  • Goal: improve Vite core performance by leveraging Rolldown
  • Items here are mostly tentative!
    • Expose plugin container as a Rolldown API
    • Introduce Rust in Vite core, using Rolldown as dependency
    • Port perf-critical Vite internal plugins to Rust. This will be done pragmatically - we will need to consider the perf gain vs. the loss of iteration flexibility caused by moving from TS to Rust for each internal plugin. The candidate will be those that are relatively stable but will yield the most perf gains.
    • Port Vite's SSR transform (used in ssrLoadModule) to Rust, eliminate SSR externals
    • Full bundled mode in Vite (for cases with too many modules)

Side Features

Don't fit in a specific milestone but good to be tackled whenever possible

  • WASM build WIP by @Brooooooklyn
  • Playground
  • Built-in profiling / build observability
  • Opinionated, zero config TypeScript library bundling
  • DTS generation + bundling (requires isolatedDeclarations)
  • CSS processing by leveraging Lightning CSS.