esbuild

@hehe

esbuild

v0.6.26

  • Fast
  • Rich benchmarks
  • Support jsx/ts (to ES6)
  • by Figma CTO (evan wallace)
  • adopted by Vite/Snowpack/HUGO
  • stats
    • 24k loc (source code)
    • 13k loc (tests)
    • 34k weekly downloads

tree -d

...

├── internal
│   ├── ast
│   ├── bundler
│   │   └── snapshots
│   ├── compat
│   ├── config
│   ├── fs
│   ├── lexer
│   ├── logging
│   ├── parser
│   ├── printer
│   ├── renamer
│   ├── resolver
│   ├── runtime
│   ├── sourcemap
│   └── test

...

代码量小,麻烦的是处理兼容/edge case/correctness,核心功能趋于稳定 (前阵子还支持了 tree shaking/code splitting)

  • parsing
    • resolver.go
    • lexer.go
    • parser.go ~10k loc
      • parser_lower.go // a ** b -> Math.pow(a, b)
      • parser_ts.go
      • parser_json.go
      • parser_sourcemap.go
  • runtime.go
    • inject js runtime
  • minify
    • printer.go
    • renamer.go

Makefile & scripts

tricks

  • lib/install.ts
    • 发布各平台的 binary (esbuild-darwin-64/esbuild-linux-64/...)
    • "postinstall": "node install.js"
    • 识别平台,从 registry 下载对应的包
  • internal/compat/table.go
    • golang 社区没有 compat-table(也没必要),esbuild 为了支持类似 --target=firefox57,safari11 的语法 (browerlist),最后通过 scripts/compat-table.js,读取 compat-table 内容自动生成 go 代码供项目使用
    • internal/lexer/unicode.go 同样由脚本生成

Is this still just an "existence proof"?

issue 329

evanw:

  • I'm not planning to abandon it.
  • I'm imagining esbuild as a kind of "linker" for the web.
  • goals
    • Be a fast bundler.
    • Inspire other bundlers to care about speed and become much faster.
    • Be a transform library for certain commonly-slow tasks to speed up other tools.
    • Add an extensibility layer to esbuild.

evanw 一点不觉得打字麻烦,乐于和社区沟通,答疑解惑动不动发长文 (对比 antd),代码注释也很多

看到希望能激励其他 bundlers 关注工具的执行效率,快哭了

推荐看全文

notes

  • 没必要被语言限制 (written in golang)
  • 没必要容忍糟糕的开发者体验 (no slow bundler)
  • 没必要都从头写,可以借点力 (test suite)
  • 没必要都从头写,也可以借其他语言库 (compat-table/unicode-table)
  • 注意:evan 还很年轻 (30 yo)

next