UNPKG

@storm-software/unbuild

Version:

A package containing `unbuild` utilities for building Storm Software libraries and applications

82 lines (79 loc) 3.21 kB
import { TypeScriptBuildOptions, TypeScriptBuildResolvedOptions, AdditionalCLIOptions } from '@storm-software/build-tools'; import { CommonOptions } from 'esbuild'; import { MkdistOptions } from 'mkdist'; import { BuildOptions, RollupBuildOptions, BuildContext, MkdistBuildEntry, BuildConfig } from 'unbuild'; type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]>; } : T; interface LoaderInputFile { path: string; extension: string; srcPath?: string; getContents: () => Promise<string> | string; } interface LoaderOutputFile { /** * relative to distDir */ path: string; srcPath?: string; extension?: string; contents?: string; declaration?: boolean; errors?: Error[]; raw?: boolean; skip?: boolean; } type LoaderResult = LoaderOutputFile[] | undefined; type LoadFile = (input: LoaderInputFile) => LoaderResult | Promise<LoaderResult>; interface LoaderOptions { ext?: "js" | "mjs" | "cjs" | "ts" | "mts" | "cts"; format?: "cjs" | "esm"; declaration?: boolean; esbuild?: CommonOptions; postcss?: false | Record<string, any>; } interface LoaderContext { loadFile: LoadFile; options: LoaderOptions; } type Loader = (input: LoaderInputFile, context: LoaderContext) => LoaderResult | Promise<LoaderResult>; type Loaders = ("js" | "vue" | "sass" | "postcss" | Loader)[]; type UnbuildOptions = Omit<Partial<BuildOptions>, "entries" | "rootDir" | "externals" | "rollupConfig" | "outDir" | "declaration" | "format" | "parallel"> & Omit<TypeScriptBuildOptions, "entry" | "format"> & { /** * The directories to run the build process out of * * @defaultValue ["{sourceRoot}"] */ entry?: string[]; /** * Path to a rollup configuration file relative to the project root */ rollup?: string | DeepPartial<RollupBuildOptions>; /** * Path to a unbuild configuration file relative to the project root */ configPath?: string; /** * Should the build process emit declaration files * * @defaultValue `true` */ emitTypes?: boolean; /** * Override the loader options used in the build process */ loaders?: Loaders | ((ctx: BuildContext, entry: MkdistBuildEntry, opts: MkdistOptions) => Loaders | Promise<Loaders>); }; type UnbuildResolvedOptions = Omit<TypeScriptBuildResolvedOptions, "entryPoints" | "external" | "emitTypes"> & BuildConfig & { /** * Path to a rollup configuration file relative to the project root */ rollup: DeepPartial<RollupBuildOptions>; outDir: string; externals: string[]; entries: BuildOptions["entries"]; declaration: BuildOptions["declaration"]; }; type UnbuildCLIOptions = AdditionalCLIOptions & Pick<UnbuildOptions, "name" | "outputPath" | "platform" | "bundle" | "target" | "watch" | "clean" | "debug" | "banner" | "footer" | "splitting" | "treeShaking" | "generatePackageJson" | "metafile" | "minify" | "includeSrc" | "verbose" | "emitTypes">; export type { DeepPartial, LoadFile, Loader, LoaderContext, LoaderInputFile, LoaderOptions, LoaderOutputFile, LoaderResult, Loaders, UnbuildCLIOptions, UnbuildOptions, UnbuildResolvedOptions };