API 参考
build
构建您的项目。
用法
ts
import { build } from 'velite'签名
ts
const build: (options?: Options) => Promise<Result>参数
options
- 类型:
Options, 参见 Options。
构建选项。
options.config
- 类型:
string
指定配置文件路径。
options.clean
- 类型:
boolean - 默认值:
false
在构建前清理输出目录。
options.watch
- 类型:
boolean - 默认值:
false
监听文件变化并在变更时重新构建。
options.logLevel
- 类型:
'debug' | 'info' | 'warn' | 'error' | 'silent' - 默认值:
'info'
日志级别。
options.strict
- 类型:
boolean - 默认值:
false
如果为 true,当任何模式验证失败时会抛出错误并终止进程。否则,仅记录警告但不会终止进程。
返回值
- 类型:
Promise<Result>, 参见 Result。
构建结果。
类型定义
Options
ts
interface Options {
/**
* 指定配置文件路径
* @default 'velite.config.{js,ts,mjs,mts,cjs,cts}'
*/
config?: string
/**
* 在构建前清理输出目录
* @default false
*/
clean?: boolean
/**
* 监听文件变化并在变更时重新构建
* @default false
*/
watch?: boolean
/**
* 日志级别
* @default 'info'
*/
logLevel?: LogLevel
}Result
ts
interface Entry {
[key: string]: any
}
/**
* 构建结果,文档文件中可能包含一个或多个条目
*/
interface Result {
[name: string]: Entry | Entry[]
}outputFile
签名
ts
const outputFile: async <T extends string | undefined>(ref: T, fromPath: string) => Promise<T>outputImage
签名
ts
const outputImage: async <T extends string | undefined>(ref: T, fromPath: string) => Promise<Image | T>cache
loaded:${path}: 已加载文件的 VFile。
...