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> {
20
20
build : BuildFn < Config >
21
21
}
22
22
23
+ const IS_PROD = process . env . NODE_ENV === 'production'
24
+
23
25
export class Bundler < C = any > {
24
26
private readonly args : Args
25
27
private config : C
@@ -36,7 +38,8 @@ export class Bundler<C = any> {
36
38
}
37
39
38
40
public getConfig ( ) : C {
39
- return this . mountConfig ( this . config )
41
+ const config = this . args . modifyBundlerConfig ( this . config , ! IS_PROD )
42
+ return this . mountConfig ( config )
40
43
}
41
44
42
45
public async createServer ( config : C ) : Promise < BundlerServer > {
@@ -48,10 +51,9 @@ export class Bundler<C = any> {
48
51
}
49
52
50
53
private mountConfig ( config : C ) : any {
51
- const { plugins, env } = this . args
52
- const dev = env === 'development'
54
+ const { plugins } = this . args
53
55
const reduce = Plugin . reduceFromPlugins < C > ( plugins )
54
56
55
- return reduce ( 'modifyBundlerConfig' , config , dev )
57
+ return reduce ( 'modifyBundlerConfig' , config , ! IS_PROD )
56
58
}
57
59
}
Original file line number Diff line number Diff line change @@ -22,14 +22,17 @@ export interface Argv {
22
22
theme : string
23
23
}
24
24
25
+ export interface ThemeConfig {
26
+ [ key : string ] : any
27
+ }
28
+
25
29
export interface Config extends Argv {
26
30
paths : Paths
27
31
plugins ?: Plugin [ ]
28
32
mdPlugins : any [ ]
29
33
hastPlugins : any [ ]
30
- themeConfig ?: {
31
- [ key : string ] : any
32
- }
34
+ themeConfig : ThemeConfig
35
+ modifyBundlerConfig < C > ( config : C , dev : boolean ) : C
33
36
}
34
37
35
38
export const args = ( yargs : any ) => {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export const loadConfig = (args: Config): Config => {
15
15
mdPlugins : [ ] ,
16
16
hastPlugins : [ ] ,
17
17
themeConfig : { } ,
18
+ modifyBundlerConfig : ( config : any ) => config ,
18
19
} )
19
20
20
21
const reduce = Plugin . reduceFromPlugins < Config > ( config . plugins )
You can’t perform that action at this time.
0 commit comments