Skip to content

Commit ce28839

Browse files
committed
fix live reload for webpack 5
1 parent 60eb00e commit ce28839

File tree

2 files changed

+6
-44
lines changed

2 files changed

+6
-44
lines changed

packages/angular-v12/angular-v12.webpack.ts

+4-37
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ export class AngularV12Webpack extends AngularWebpack {
7777
delete webpackConfig.devServer.watchOptions;
7878

7979
// Moved sockPath to client.webSocketURL.pathname option
80-
webpackConfig.devServer.client.webSocketURL = webpackConfig.devServer.client.webSocketURL || {};
81-
webpackConfig.devServer.client.webSocketURL.pathname = webpackConfig.devServer.sockPath;
80+
// We let webpack handle that now
8281
delete webpackConfig.devServer.sockPath;
8382

8483
// Removed stats in favor of the stats options from webpack
@@ -90,6 +89,9 @@ export class AngularV12Webpack extends AngularWebpack {
9089
// Removed watch to avoid "DEP_WEBPACK_WATCH_WITHOUT_CALLBACK" warning
9190
delete webpackConfig.watch;
9291

92+
// Removed in favor of manual setup entries.
93+
delete webpackConfig.devServer.injectClient;
94+
9395
// Cleaning up undefined values
9496
Object.keys(webpackConfig.devServer).forEach((option) => {
9597
if (typeof webpackConfig.devServer[option] === 'undefined') {
@@ -166,41 +168,6 @@ export class AngularV12Webpack extends AngularWebpack {
166168
{}
167169
);
168170

169-
// @ts-ignore
170-
if (webpackOptions.liveReload && !webpackOptions.hmr) {
171-
// This is needed because we cannot use the inline option directly in the config
172-
// because of the SuppressExtractedTextChunksWebpackPlugin
173-
// Consider not using SuppressExtractedTextChunksWebpackPlugin when liveReload is enable.
174-
// tslint:disable-next-line: no-any
175-
addDevServerEntrypoints(webpackConfig as any, {
176-
...(webpackConfig as any).devServer,
177-
inline: true,
178-
});
179-
180-
// Remove live-reload code from all entrypoints but not main.
181-
// Otherwise, this will break SuppressExtractedTextChunksWebpackPlugin because
182-
// 'addDevServerEntrypoints' adds additional entry-points to all entries.
183-
if (
184-
webpackConfig.entry &&
185-
typeof webpackConfig.entry === 'object' &&
186-
!Array.isArray(webpackConfig.entry) &&
187-
webpackConfig.entry.main
188-
) {
189-
for (const [key, value] of Object.entries(webpackConfig.entry)) {
190-
if (key === 'main' || !Array.isArray(value)) {
191-
// eslint-disable-next-line no-continue
192-
continue;
193-
}
194-
195-
const webpackClientScriptIndex = value.findIndex((x) => x.includes('webpack-dev-server/client/index.js'));
196-
if (webpackClientScriptIndex >= 0) {
197-
// Remove the webpack-dev-server/client script from array.
198-
value.splice(webpackClientScriptIndex, 1);
199-
}
200-
}
201-
}
202-
}
203-
204171
// @ts-ignore
205172
if (webpackOptions.hmr) {
206173
logger.warn(tags.stripIndents`NOTICE: Hot Module Replacement (HMR) is enabled for the dev server.

packages/angular-v12/webpack/webpack5.serve.config.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function webpack5ServeConfigFactory(
9090
serveIndex: true,
9191
// Can be:
9292
// watch: {} (options for the `watch` option you can find https://github.com/paulmillr/chokidar)
93-
watch: true,
93+
watch: false,
9494
},
9595
],
9696

@@ -110,12 +110,7 @@ export function webpack5ServeConfigFactory(
110110
},
111111

112112
client: {
113-
overlay: false,
114-
// public, sockHost, sockPath, and sockPort options were removed in favor client.webSocketURL option:
115-
webSocketURL: {
116-
pathname: `_hmr/${devServerID}`,
117-
// port automatically matches the website
118-
},
113+
overlay: false
119114
},
120115

121116
webSocketServer: {

0 commit comments

Comments
 (0)