obuild
Version:
Zero-config ESM/TS package builder
89 lines (88 loc) • 2.51 kB
text/typescript
import { InputOptions, MinifyOptions, OutputOptions, RolldownBuild, RolldownPluginOption } from "rolldown";
import { Options } from "rolldown-plugin-dts";
import { MinifyOptions as MinifyOptions$1 } from "oxc-minify";
import { TransformOptions } from "oxc-transform";
//#region src/types.d.ts
interface BuildContext {
pkgDir: string;
pkg: {
name: string;
} & Record<string, unknown>;
}
type _BuildEntry = {
/**
* Output directory relative to project root.
*
* Defaults to `dist/` if not provided.
*/
outDir?: string;
/**
* Avoid actual build but instead link to the source files.
*/
stub?: boolean;
};
type BundleEntry = _BuildEntry & {
type: "bundle";
/**
* Entry point(s) to bundle relative to the project root.
* */
input: string | string[];
/**
* Minify the output using rolldown.
*
* Defaults to `false` if not provided.
*/
minify?: boolean | "dce-only" | MinifyOptions;
/**
* Options passed to rolldown.
*
* See [rolldown config options](https://rolldown.rs/reference/config-options) for more details.
*/
rolldown?: InputOptions & {
plugins?: RolldownPluginOption[];
};
/**
* Declaration generation options.
*
* See [rolldown-plugin-dts](https://github.com/sxzz/rolldown-plugin-dts) for more details.
*
* Options are inferred from the `tsconfig.json` file if available.
*
* Set to `false` to disable.
*/
dts?: boolean | Options;
};
type TransformEntry = _BuildEntry & {
type: "transform";
/**
* Directory to transform relative to the project root.
*/
input: string;
/**
* Minify the output using oxc-minify.
*
* Defaults to `false` if not provided.
*/
minify?: boolean | MinifyOptions$1;
/**
* Options passed to oxc-transform.
*
* See [oxc-transform](https://www.npmjs.com/package/oxc-transform) for more details.
*/
oxc?: TransformOptions;
};
type BuildEntry = BundleEntry | TransformEntry;
interface BuildHooks {
start?: (ctx: BuildContext) => void | Promise<void>;
end?: (ctx: BuildContext) => void | Promise<void>;
entries?: (entries: BuildEntry[], ctx: BuildContext) => void | Promise<void>;
rolldownConfig?: (cfg: InputOptions, ctx: BuildContext) => void | Promise<void>;
rolldownOutput?: (cfg: OutputOptions, res: RolldownBuild, ctx: BuildContext) => void | Promise<void>;
}
interface BuildConfig {
cwd?: string | URL;
entries?: (BuildEntry | string)[];
hooks?: BuildHooks;
}
//#endregion
export { BuildConfig, BuildEntry, BundleEntry, TransformEntry };