Skip to content

命令行接口

基本用法

sh
robuild [entries...] [options]

选项

基础选项

选项简写说明
--config <file>-c指定配置文件
--no-config禁用配置文件
--dir <dir>工作目录(默认: .
--out-dir <dir>-d输出目录(默认: dist
--watch-w监听模式
--stubStub 开发模式

输出选项

选项说明
--format <format>-f
--platform <platform>目标平台: browser, node, neutral
--target <target>ES 版本: es2015, es2020, esnext
--global-name <name>IIFE/UMD 全局变量名

优化选项

选项说明
--minify压缩代码
--sourcemap生成 source map
--splitting代码分割
--treeshakeTree shaking(默认开启)

类型声明

选项说明
--dts生成类型声明文件
--dts-only仅生成类型声明

依赖处理

选项说明
--external <module>外部化依赖
--no-external <module>强制打包依赖
--skip-node-modules跳过 node_modules

其他选项

选项说明
--clean清理输出目录
--no-clean禁用清理
--shims启用兼容性垫片
--unbundle保留文件结构不打包
--generate-exports生成 package.json exports
--on-success <cmd>构建成功后执行命令
--log-level <level>-l
--fail-on-warn警告时失败
--ignore-watch <pattern>监听模式忽略文件
--from-vite从 Vite 配置加载
--cjs-default <mode>CJS 默认导出处理: true, false, auto

示例

基本构建

sh
robuild ./src/index.ts

多格式输出

sh
robuild ./src/index.ts --format esm --format cjs

浏览器库

sh
robuild ./src/index.ts --format iife --global-name MyLib --platform browser

CLI 工具

sh
robuild ./src/cli.ts --platform node --minify

Transform 模式

sh
robuild ./src/runtime/:./dist/runtime

监听模式

sh
robuild ./src/index.ts -w

开发模式

sh
robuild ./src/index.ts --stub

使用配置文件

sh
robuild                           # 使用 build.config.ts
robuild --config custom.config.ts # 指定配置文件

package.json 脚本

package.json
json
{
  "scripts": {
    "build": "robuild ./src/index.ts",
    "dev": "robuild ./src/index.ts --stub",
    "watch": "robuild ./src/index.ts -w"
  }
}

下一步

Released under the MIT License.