Skip to content

Commit

Permalink
feat(docz-core): add modifyBundlerConfig configuration property
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jun 9, 2018
1 parent d6c5506 commit ec04bee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 6 additions & 4 deletions packages/docz-core/src/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface BundlerConstructor<Config> {
build: BuildFn<Config>
}

const IS_PROD = process.env.NODE_ENV === 'production'

export class Bundler<C = any> {
private readonly args: Args
private config: C
Expand All @@ -36,7 +38,8 @@ export class Bundler<C = any> {
}

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<BundlerServer> {
Expand All @@ -48,10 +51,9 @@ export class Bundler<C = any> {
}

private mountConfig(config: C): any {
const { plugins, env } = this.args
const dev = env === 'development'
const { plugins } = this.args
const reduce = Plugin.reduceFromPlugins<C>(plugins)

return reduce('modifyBundlerConfig', config, dev)
return reduce('modifyBundlerConfig', config, !IS_PROD)
}
}
9 changes: 6 additions & 3 deletions packages/docz-core/src/commands/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<C>(config: C, dev: boolean): C
}

export const args = (yargs: any) => {
Expand Down
1 change: 1 addition & 0 deletions packages/docz-core/src/utils/load-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const loadConfig = (args: Config): Config => {
mdPlugins: [],
hastPlugins: [],
themeConfig: {},
modifyBundlerConfig: (config: any) => config,
})

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

0 comments on commit ec04bee

Please sign in to comment.