Skip to content

Commit c614506

Browse files
alan-agius4mgechev
authored andcommitted
fix(@angular-devkit/build-webpack): allow runWebpackDevServer to accept a webpackDevServerFactory
1 parent b9baa18 commit c614506

File tree

2 files changed

+25
-2
lines changed
  • packages/angular_devkit
    • build_angular/src/dev-server
    • build_webpack/src/webpack-dev-server

2 files changed

+25
-2
lines changed

packages/angular_devkit/build_angular/src/dev-server/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,15 @@ export function serveWebpackBrowser(
277277
`);
278278
}
279279

280-
return runWebpackDevServer(webpackConfig, context, { logging: loggingFn }).pipe(
280+
return runWebpackDevServer(
281+
webpackConfig,
282+
context,
283+
{
284+
logging: loggingFn,
285+
webpackFactory: require('webpack') as typeof webpack,
286+
webpackDevServerFactory: require('webpack-dev-server') as typeof WebpackDevServer,
287+
},
288+
).pipe(
281289
map(buildEvent => {
282290
// Resolve serve address.
283291
const serverAddress = url.format({

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { getEmittedFiles } from '../utils';
1616
import { BuildResult, WebpackFactory, WebpackLoggingCallback } from '../webpack';
1717
import { Schema as WebpackDevServerBuilderSchema } from './schema';
1818

19+
export type WebpackDevServerFactory = typeof WebpackDevServer;
20+
1921
export type DevServerBuildOutput = BuildResult & {
2022
port: number;
2123
family: string;
@@ -29,6 +31,7 @@ export function runWebpackDevServer(
2931
devServerConfig?: WebpackDevServer.Configuration,
3032
logging?: WebpackLoggingCallback,
3133
webpackFactory?: WebpackFactory,
34+
webpackDevServerFactory?: WebpackDevServerFactory,
3235
} = {},
3336
): Observable<DevServerBuildOutput> {
3437
const createWebpack = (c: webpack.Configuration) => {
@@ -43,6 +46,18 @@ export function runWebpackDevServer(
4346
return of(webpack(c));
4447
}
4548
};
49+
50+
const createWebpackDevServer = (
51+
webpack: webpack.Compiler | webpack.MultiCompiler,
52+
config: WebpackDevServer.Configuration,
53+
) => {
54+
if (options.webpackDevServerFactory) {
55+
return new options.webpackDevServerFactory(webpack, config);
56+
}
57+
58+
return new WebpackDevServer(webpack, config);
59+
};
60+
4661
const log: WebpackLoggingCallback = options.logging
4762
|| ((stats, config) => context.logger.info(stats.toString(config.stats)));
4863

@@ -55,7 +70,7 @@ export function runWebpackDevServer(
5570

5671
return createWebpack(config).pipe(
5772
switchMap(webpackCompiler => new Observable<DevServerBuildOutput>(obs => {
58-
const server = new WebpackDevServer(webpackCompiler, devServerConfig);
73+
const server = createWebpackDevServer(webpackCompiler, devServerConfig);
5974
let result: DevServerBuildOutput;
6075

6176
webpackCompiler.hooks.done.tap('build-webpack', (stats) => {

0 commit comments

Comments
 (0)