@@ -40,7 +40,7 @@ function createBrowserLoggingCallback(verbose, logger) {
40
40
} ;
41
41
}
42
42
exports . createBrowserLoggingCallback = createBrowserLoggingCallback ;
43
- async function buildBrowserWebpackConfigFromContext ( options , context , host ) {
43
+ async function buildBrowserWebpackConfigFromContext ( options , context , host = new node_1 . NodeJsSyncHost ( ) ) {
44
44
return webpack_browser_config_1 . generateBrowserWebpackConfigFromContext ( options , context , wco => [
45
45
webpack_configs_1 . getCommonConfig ( wco ) ,
46
46
webpack_configs_1 . getBrowserConfig ( wco ) ,
@@ -75,30 +75,26 @@ function getCompilerConfig(wco) {
75
75
}
76
76
return { } ;
77
77
}
78
+ async function initialize ( options , context , host , webpackConfigurationTransform ) {
79
+ const { config, workspace } = await buildBrowserWebpackConfigFromContext ( options , context , host ) ;
80
+ let transformedConfig ;
81
+ if ( webpackConfigurationTransform ) {
82
+ transformedConfig = [ ] ;
83
+ for ( const c of config ) {
84
+ transformedConfig . push ( await webpackConfigurationTransform ( c ) ) ;
85
+ }
86
+ }
87
+ if ( options . deleteOutputPath ) {
88
+ await utils_1 . deleteOutputDir ( core_1 . normalize ( context . workspaceRoot ) , core_1 . normalize ( options . outputPath ) , host ) . toPromise ( ) ;
89
+ }
90
+ return { config : transformedConfig || config , workspace } ;
91
+ }
78
92
function buildWebpackBrowser ( options , context , transforms = { } ) {
79
93
const host = new node_1 . NodeJsSyncHost ( ) ;
80
94
const root = core_1 . normalize ( context . workspaceRoot ) ;
81
- const configFn = transforms . config ;
82
- const outputFn = transforms . output ;
83
95
const loggingFn = transforms . logging
84
96
|| createBrowserLoggingCallback ( ! ! options . verbose , context . logger ) ;
85
- // This makes a host observable into a cold one. This is because we want to wait until
86
- // subscription before calling buildBrowserWebpackConfigFromContext, which can throw.
87
- return rxjs_1 . of ( null ) . pipe ( operators_1 . switchMap ( ( ) => rxjs_1 . from ( buildBrowserWebpackConfigFromContext ( options , context , host ) ) ) , operators_1 . switchMap ( ( { workspace, config } ) => {
88
- if ( configFn ) {
89
- return rxjs_1 . combineLatest ( config . map ( config => configFn ( workspace , config ) ) ) . pipe ( operators_1 . map ( config => ( { workspace, config } ) ) ) ;
90
- }
91
- else {
92
- return rxjs_1 . of ( { workspace, config } ) ;
93
- }
94
- } ) , operators_1 . switchMap ( ( { workspace, config } ) => {
95
- if ( options . deleteOutputPath ) {
96
- return utils_1 . deleteOutputDir ( root , core_1 . normalize ( options . outputPath ) , host ) . pipe ( operators_1 . map ( ( ) => ( { workspace, config } ) ) ) ;
97
- }
98
- else {
99
- return rxjs_1 . of ( { workspace, config } ) ;
100
- }
101
- } ) , operators_1 . switchMap ( ( { workspace, config : configs } ) => {
97
+ return rxjs_1 . from ( initialize ( options , context , host , transforms . webpackConfiguration ) ) . pipe ( operators_1 . switchMap ( ( { workspace, config : configs } ) => {
102
98
const projectName = context . target
103
99
? context . target . project : workspace . getDefaultProjectName ( ) ;
104
100
if ( ! projectName ) {
@@ -141,7 +137,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
141
137
...event ,
142
138
// If we use differential loading, both configs have the same outputs
143
139
outputPath : path . resolve ( context . workspaceRoot , options . outputPath ) ,
144
- } ) ) , operators_1 . concatMap ( output => outputFn ? outputFn ( output ) : rxjs_1 . of ( output ) ) ) ;
140
+ } ) ) ) ;
145
141
} ) ) ;
146
142
}
147
143
exports . buildWebpackBrowser = buildWebpackBrowser ;
0 commit comments