esbuild

  • esbuild 是一个极其快速的 JavaScript 和 TypeScript 打包工具和构建工具。它采用了 Go 语言 编写,因此在性能上非常突出,尤其适用于需要快速构建和打包的项目。esbuild 的设计目标是提供一个 零配置、超高性能 的工具,能够大幅缩短构建时间,尤其在大型项目中表现尤为明显。

安装

npm install -g esbuild

基本使用

构建命令:

esbuild src/index.js --outfile=dist/bundle.js
# 将 src/index.js 打包成 dist/bundle.js

构建 TypeScript 文件:

esbuild src/index.ts --outfile=dist/index.js

配置文件

  • 虽然 esbuild 是一个零配置工具,但你也可以使用 JavaScript 配置文件来进行自定义配置

示例:

const esbuild = require('esbuild');

esbuild.build({
  entryPoints: ['src/index.ts'],
  outfile: 'dist/bundle.js',
  minify: true,
  bundle: true,
}).catch(() => process.exit(1));

对比

https://img.zhaoweiguo.com/uPic/2025/03/lyckqW.png