This repository was archived by the owner on Jan 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff 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+
2325export 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}
Original file line number Diff line number Diff line change @@ -22,14 +22,17 @@ export interface Argv {
2222 theme : string
2323}
2424
25+ export interface ThemeConfig {
26+ [ key : string ] : any
27+ }
28+
2529export 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
3538export const args = ( yargs : any ) => {
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments