7
7
*/
8
8
import { BuilderContext , BuilderOutput , createBuilder } from '@angular-devkit/architect' ;
9
9
import { getSystemPath , json , normalize , resolve } from '@angular-devkit/core' ;
10
- import { Observable , from , of } from 'rxjs' ;
10
+ import { Observable , from , isObservable , of } from 'rxjs' ;
11
11
import { switchMap } from 'rxjs/operators' ;
12
12
import * as webpack from 'webpack' ;
13
13
import { EmittedFiles , getEmittedFiles } from '../utils' ;
@@ -19,7 +19,7 @@ export interface WebpackLoggingCallback {
19
19
( stats : webpack . Stats , config : webpack . Configuration ) : void ;
20
20
}
21
21
export interface WebpackFactory {
22
- ( config : webpack . Configuration ) : Observable < webpack . Compiler > ;
22
+ ( config : webpack . Configuration ) : Observable < webpack . Compiler > | webpack . Compiler ;
23
23
}
24
24
25
25
export type BuildResult = BuilderOutput & {
@@ -35,7 +35,18 @@ export function runWebpack(
35
35
webpackFactory ?: WebpackFactory ,
36
36
} = { } ,
37
37
) : Observable < BuildResult > {
38
- const createWebpack = options . webpackFactory || ( config => of ( webpack ( config ) ) ) ;
38
+ const createWebpack = ( c : webpack . Configuration ) => {
39
+ if ( options . webpackFactory ) {
40
+ const result = options . webpackFactory ( c ) ;
41
+ if ( isObservable ( result ) ) {
42
+ return result ;
43
+ } else {
44
+ return of ( result ) ;
45
+ }
46
+ } else {
47
+ return of ( webpack ( c ) ) ;
48
+ }
49
+ } ;
39
50
const log : WebpackLoggingCallback = options . logging
40
51
|| ( ( stats , config ) => context . logger . info ( stats . toString ( config . stats ) ) ) ;
41
52
0 commit comments