Skip to content

Commit

Permalink
fix(dts-plugin): do not regen types on hmr if dev false
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy committed Nov 14, 2024
1 parent 7facc10 commit e9fd573
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/honest-yaks-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/dts-plugin': patch
---

ensure when dev is false that type generation only runs once
6 changes: 5 additions & 1 deletion packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
return fn;
};
const generateTypesFn = getGenerateTypesFn();

let compiledOnce = false;
compiler.hooks.thisCompilation.tap('mf:generateTypes', (compilation) => {
compilation.hooks.processAssets.tapPromise(
{
Expand All @@ -82,6 +82,9 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER,
},
async () => {
if (pluginOptions.dev === false && compiledOnce) {
return;
}
try {
const { zipTypesPath, apiTypesPath, zipName, apiFileName } =
retrieveTypesAssetsInfo(finalOptions.remote);
Expand Down Expand Up @@ -124,6 +127,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
),
);
}
compiledOnce = true;
} catch (err) {
console.error(err);
}
Expand Down

0 comments on commit e9fd573

Please sign in to comment.