diff --git a/.gitignore b/.gitignore index a99d3a9..5466e5e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist types .gen .nyc_output +.idea/ diff --git a/src/build.ts b/src/build.ts index 4b7848d..de30dbd 100644 --- a/src/build.ts +++ b/src/build.ts @@ -22,7 +22,7 @@ import { createJiti } from "jiti"; export async function build( rootDir: string, stub: boolean, - inputConfig: BuildConfig = {}, + inputConfig: BuildConfig & { config?: string } = {}, ): Promise { // Determine rootDir rootDir = resolve(process.cwd(), rootDir || "."); @@ -31,7 +31,10 @@ export async function build( const jiti = createJiti(rootDir); const _buildConfig: BuildConfig | BuildConfig[] = - (await jiti.import("./build.config", { try: true, default: true })) || {}; + (await jiti.import(inputConfig?.config || "./build.config", { + try: !inputConfig.config, + default: true, + })) || {}; const buildConfigs = ( Array.isArray(_buildConfig) ? _buildConfig : [_buildConfig] diff --git a/src/cli.ts b/src/cli.ts index d2b2641..47f0ae1 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -17,6 +17,14 @@ const main = defineCommand({ description: "The directory to build", required: false, }, + config: { + type: "string", + description: [ + "The configuration file to use relative to the current working directory.", + " Unbuild tries to read `build.config` from the build `DIR` by default.", + "", + ].join("\n"), + }, watch: { type: "boolean", description: "Watch the src dir and rebuild on change (experimental)", @@ -38,6 +46,7 @@ const main = defineCommand({ const rootDir = resolve(process.cwd(), args.dir || "."); await build(rootDir, args.stub, { sourcemap: args.sourcemap, + config: args.config ? resolve(args.config) : undefined, stub: args.stub, watch: args.watch, rollup: {