Skip to content

Commit 5c0c277

Browse files
Prevent duplicate asset emission and avoid rebuild loops in Webpack configuration
1 parent b08bd00 commit 5c0c277

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

code/builders/builder-webpack5/src/plugins/webpack-inject-mocker-runtime-plugin.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ export class WebpackInjectMockerRuntimePlugin {
5959

6060
// Use the documented `emitAsset` method to add the pre-bundled runtime script
6161
// to the compilation's assets. This is the standard Webpack way.
62-
compilation.emitAsset(
63-
runtimeAssetName,
64-
new compiler.webpack.sources.RawSource(runtimeScriptContent)
65-
);
62+
if (!compilation.getAsset(runtimeAssetName)) {
63+
compilation.emitAsset(
64+
runtimeAssetName,
65+
new compiler.webpack.sources.RawSource(runtimeScriptContent)
66+
);
67+
data.assets.js.unshift(runtimeAssetName);
68+
}
6669

6770
// Prepend the name of our new asset to the list of JavaScript files, once.
6871
// HtmlWebpackPlugin will automatically create a <script> tag for it
6972
// and place it at the beginning of the body scripts.
70-
if (!data.assets.js.includes(runtimeAssetName)) {
71-
data.assets.js.unshift(runtimeAssetName);
72-
}
7373
cb(null, data);
7474
} catch (error) {
7575
// In case of an error (e.g., file not found), pass it to Webpack's compilation.

code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dirname, join, resolve } from 'node:path';
1+
import { join, posix, resolve } from 'node:path';
22
import { fileURLToPath } from 'node:url';
33

44
import {
@@ -126,7 +126,8 @@ export default async (
126126
logging: 'error',
127127
},
128128
watchOptions: {
129-
ignored: /node_modules/,
129+
// Ignore node_modules and the output directory to avoid rebuild loops
130+
ignored: ['**/node_modules', posix.resolve(workingDir, outputDir)],
130131
},
131132
externals,
132133
ignoreWarnings: [

0 commit comments

Comments
 (0)