Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --config to the CLI #440

Merged
merged 8 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
types
.gen
.nyc_output
.idea/
7 changes: 5 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createJiti } from "jiti";
export async function build(
rootDir: string,
stub: boolean,
inputConfig: BuildConfig = {},
inputConfig: BuildConfig & { config?: string } = {},
): Promise<void> {
// Determine rootDir
rootDir = resolve(process.cwd(), rootDir || ".");
Expand All @@ -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]
Expand Down
9 changes: 9 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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: {
Expand Down