diff --git a/packages/docz-core/src/Bundler.ts b/packages/docz-core/src/Bundler.ts index 2a49bdf90..28065c4bc 100644 --- a/packages/docz-core/src/Bundler.ts +++ b/packages/docz-core/src/Bundler.ts @@ -20,6 +20,8 @@ export interface BundlerConstructor { build: BuildFn } +const IS_PROD = process.env.NODE_ENV === 'production' + export class Bundler { private readonly args: Args private config: C @@ -36,7 +38,8 @@ export class Bundler { } public getConfig(): C { - return this.mountConfig(this.config) + const config = this.args.modifyBundlerConfig(this.config, !IS_PROD) + return this.mountConfig(config) } public async createServer(config: C): Promise { @@ -48,10 +51,9 @@ export class Bundler { } private mountConfig(config: C): any { - const { plugins, env } = this.args - const dev = env === 'development' + const { plugins } = this.args const reduce = Plugin.reduceFromPlugins(plugins) - return reduce('modifyBundlerConfig', config, dev) + return reduce('modifyBundlerConfig', config, !IS_PROD) } } diff --git a/packages/docz-core/src/commands/args.ts b/packages/docz-core/src/commands/args.ts index 86e0bfe60..44de2d214 100644 --- a/packages/docz-core/src/commands/args.ts +++ b/packages/docz-core/src/commands/args.ts @@ -22,14 +22,17 @@ export interface Argv { theme: string } +export interface ThemeConfig { + [key: string]: any +} + export interface Config extends Argv { paths: Paths plugins?: Plugin[] mdPlugins: any[] hastPlugins: any[] - themeConfig?: { - [key: string]: any - } + themeConfig: ThemeConfig + modifyBundlerConfig(config: C, dev: boolean): C } export const args = (yargs: any) => { diff --git a/packages/docz-core/src/utils/load-config.ts b/packages/docz-core/src/utils/load-config.ts index efcaff177..2618f2cdd 100644 --- a/packages/docz-core/src/utils/load-config.ts +++ b/packages/docz-core/src/utils/load-config.ts @@ -15,6 +15,7 @@ export const loadConfig = (args: Config): Config => { mdPlugins: [], hastPlugins: [], themeConfig: {}, + modifyBundlerConfig: (config: any) => config, }) const reduce = Plugin.reduceFromPlugins(config.plugins)