Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit ec04bee

Browse files
committed
feat(docz-core): add modifyBundlerConfig configuration property
1 parent d6c5506 commit ec04bee

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

packages/docz-core/src/Bundler.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface BundlerConstructor<Config> {
2020
build: BuildFn<Config>
2121
}
2222

23+
const IS_PROD = process.env.NODE_ENV === 'production'
24+
2325
export class Bundler<C = any> {
2426
private readonly args: Args
2527
private config: C
@@ -36,7 +38,8 @@ export class Bundler<C = any> {
3638
}
3739

3840
public getConfig(): C {
39-
return this.mountConfig(this.config)
41+
const config = this.args.modifyBundlerConfig(this.config, !IS_PROD)
42+
return this.mountConfig(config)
4043
}
4144

4245
public async createServer(config: C): Promise<BundlerServer> {
@@ -48,10 +51,9 @@ export class Bundler<C = any> {
4851
}
4952

5053
private mountConfig(config: C): any {
51-
const { plugins, env } = this.args
52-
const dev = env === 'development'
54+
const { plugins } = this.args
5355
const reduce = Plugin.reduceFromPlugins<C>(plugins)
5456

55-
return reduce('modifyBundlerConfig', config, dev)
57+
return reduce('modifyBundlerConfig', config, !IS_PROD)
5658
}
5759
}

packages/docz-core/src/commands/args.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ export interface Argv {
2222
theme: string
2323
}
2424

25+
export interface ThemeConfig {
26+
[key: string]: any
27+
}
28+
2529
export interface Config extends Argv {
2630
paths: Paths
2731
plugins?: Plugin[]
2832
mdPlugins: any[]
2933
hastPlugins: any[]
30-
themeConfig?: {
31-
[key: string]: any
32-
}
34+
themeConfig: ThemeConfig
35+
modifyBundlerConfig<C>(config: C, dev: boolean): C
3336
}
3437

3538
export const args = (yargs: any) => {

packages/docz-core/src/utils/load-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const loadConfig = (args: Config): Config => {
1515
mdPlugins: [],
1616
hastPlugins: [],
1717
themeConfig: {},
18+
modifyBundlerConfig: (config: any) => config,
1819
})
1920

2021
const reduce = Plugin.reduceFromPlugins<Config>(config.plugins)

0 commit comments

Comments
 (0)