配置文件
robuild 支持使用配置文件来定义构建选项,提供更灵活的配置方式。
支持的配置文件
robuild 会自动查找以下配置文件:
build.config.ts(推荐)build.config.mjsbuild.config.js
基本用法
build.config.ts
ts
import { defineConfig } from 'robuild'
export default defineConfig({
entries: [
{
type: 'bundle',
input: './src/index.ts',
format: ['esm', 'cjs'],
dts: true,
},
],
})1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
指定配置文件
通过 --config 选项指定自定义配置文件:
sh
robuild --config custom.config.ts1
禁用配置文件:
sh
robuild --no-config ./src/index.ts1
配置风格
entries 风格(unbuild 风格)
build.config.ts
ts
import { defineConfig } from 'robuild'
export default defineConfig({
entries: [
{
type: 'bundle',
input: './src/index.ts',
format: ['esm', 'cjs'],
},
{
type: 'transform',
input: './src/runtime',
outDir: './dist/runtime',
},
],
})1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
扁平风格(tsup 风格)
build.config.ts
ts
import { defineConfig } from 'robuild'
export default defineConfig({
entry: ['./src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
minify: true,
})1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
TIP
两种风格可以混合使用。当同时存在 entries 和 entry 时,entries 优先。
从 Vite 配置加载
使用 --from-vite 选项可以从 Vite 配置文件加载配置:
sh
robuild --from-vite1
这对于已有 Vite 项目的集成非常有用。
