Skip to content

构建模式

robuild 支持两种构建模式:Bundle 模式Transform 模式

Bundle 模式

将多个文件打包成单个文件,适合库发布。

基本用法

sh
robuild ./src/index.ts

配置示例

build.config.ts
ts
import { defineConfig } from 'robuild'

export default defineConfig({
  entries: [
    {
      type: 'bundle',
      input: './src/index.ts',
      format: ['esm', 'cjs'],
      dts: true,
      minify: true,
    },
  ],
})

输出结构

dist/
├── index.mjs      # ESM 格式
├── index.cjs      # CJS 格式
├── index.d.mts    # 类型声明
└── _chunks/       # 代码分割文件

特点

  • 单文件输出
  • 支持代码分割
  • 自动处理外部依赖
  • 生成类型声明

Transform 模式

转换目录中的所有文件,保持文件结构,适合运行时文件。

基本用法

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

配置示例

build.config.ts
ts
import { defineConfig } from 'robuild'

export default defineConfig({
  entries: [
    {
      type: 'transform',
      input: './src/runtime',
      outDir: './dist/runtime',
    },
  ],
})

输出结构

dist/runtime/
├── index.mjs      # 转换后的文件
├── index.d.mts    # 类型声明
├── utils.mjs
└── utils.d.mts

特点

  • 保持目录结构
  • 文件级转换
  • 构建速度快

模式对比

特性Bundle 模式Transform 模式
输出单文件多文件
结构扁平化保持原结构
依赖打包/外部化重写路径
代码分割支持不支持
适用库发布运行时文件

混合使用

build.config.ts
ts
import { defineConfig } from 'robuild'

export default defineConfig({
  entries: [
    // 主库 - Bundle
    {
      type: 'bundle',
      input: './src/index.ts',
      dts: true,
    },
    // 运行时 - Transform
    {
      type: 'transform',
      input: './src/runtime',
      outDir: './dist/runtime',
    },
  ],
})

下一步

Released under the MIT License.