Skip to content

Commit 9f5c0f3

Browse files
clydindgp1130
authored andcommitted
refactor(@angular-devkit/build-webpack): allow a webpack factory to be used directly
1 parent 2fc3fab commit 9f5c0f3

File tree

2 files changed

+27
-5
lines changed
  • packages/angular_devkit/build_webpack/src

2 files changed

+27
-5
lines changed

packages/angular_devkit/build_webpack/src/webpack-dev-server/index.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { BuilderContext, createBuilder } from '@angular-devkit/architect';
99
import { getSystemPath, json, normalize, resolve } from '@angular-devkit/core';
1010
import * as net from 'net';
11-
import { Observable, from, of } from 'rxjs';
11+
import { Observable, from, isObservable, of } from 'rxjs';
1212
import { switchMap } from 'rxjs/operators';
1313
import * as webpack from 'webpack';
1414
import * as WebpackDevServer from 'webpack-dev-server';
@@ -31,7 +31,18 @@ export function runWebpackDevServer(
3131
webpackFactory?: WebpackFactory,
3232
} = {},
3333
): Observable<DevServerBuildOutput> {
34-
const createWebpack = options.webpackFactory || (config => of(webpack(config)));
34+
const createWebpack = (c: webpack.Configuration) => {
35+
if (options.webpackFactory) {
36+
const result = options.webpackFactory(c);
37+
if (isObservable(result)) {
38+
return result;
39+
} else {
40+
return of(result);
41+
}
42+
} else {
43+
return of(webpack(c));
44+
}
45+
};
3546
const log: WebpackLoggingCallback = options.logging
3647
|| ((stats, config) => context.logger.info(stats.toString(config.stats)));
3748

packages/angular_devkit/build_webpack/src/webpack/index.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
99
import { getSystemPath, json, normalize, resolve } from '@angular-devkit/core';
10-
import { Observable, from, of } from 'rxjs';
10+
import { Observable, from, isObservable, of } from 'rxjs';
1111
import { switchMap } from 'rxjs/operators';
1212
import * as webpack from 'webpack';
1313
import { EmittedFiles, getEmittedFiles } from '../utils';
@@ -19,7 +19,7 @@ export interface WebpackLoggingCallback {
1919
(stats: webpack.Stats, config: webpack.Configuration): void;
2020
}
2121
export interface WebpackFactory {
22-
(config: webpack.Configuration): Observable<webpack.Compiler>;
22+
(config: webpack.Configuration): Observable<webpack.Compiler> | webpack.Compiler;
2323
}
2424

2525
export type BuildResult = BuilderOutput & {
@@ -35,7 +35,18 @@ export function runWebpack(
3535
webpackFactory?: WebpackFactory,
3636
} = {},
3737
): 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+
};
3950
const log: WebpackLoggingCallback = options.logging
4051
|| ((stats, config) => context.logger.info(stats.toString(config.stats)));
4152

0 commit comments

Comments
 (0)