From addd3d4be04f1159a46e2373d8170771b1a6d575 Mon Sep 17 00:00:00 2001 From: easy1090 Date: Mon, 16 Dec 2024 19:55:16 +0800 Subject: [PATCH] fix: tile graph with reportDir --- .../build-utils/build/chunks/generateTileGraph.ts | 15 ++++++++++++--- .../plugins/ensureModulesChunkGraph.ts | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/core/src/build-utils/build/chunks/generateTileGraph.ts b/packages/core/src/build-utils/build/chunks/generateTileGraph.ts index 67d48c28..949208ed 100644 --- a/packages/core/src/build-utils/build/chunks/generateTileGraph.ts +++ b/packages/core/src/build-utils/build/chunks/generateTileGraph.ts @@ -10,6 +10,7 @@ type IGenerateReportOpts = { reportTitle?: string; bundleDir?: string; openBrowser?: boolean; + reportDir?: string; }; async function generateJSONReportUtil( bundleStats: Plugin.BaseStats, @@ -33,14 +34,22 @@ export async function generateTileGraph( buildOutputPath: string, ) { try { - const { reportFilename } = opts; + const { reportFilename, reportDir } = opts; await generateJSONReportUtil(bundleStats, { ...opts, openBrowser: false, - bundleDir: buildOutputPath, + bundleDir: reportDir || buildOutputPath, }); - return path.join(buildOutputPath, `${reportFilename}`); + return path.join( + reportDir + ? path.resolve( + buildOutputPath, + path.relative(buildOutputPath, reportDir), + ) + : buildOutputPath, + `${reportFilename}`, + ); } catch (e) { debug(() => `Generate webpack-bundle-analyzer tile graph has error:${e}`); return null; diff --git a/packages/core/src/inner-plugins/plugins/ensureModulesChunkGraph.ts b/packages/core/src/inner-plugins/plugins/ensureModulesChunkGraph.ts index 647953d2..443c69cd 100644 --- a/packages/core/src/inner-plugins/plugins/ensureModulesChunkGraph.ts +++ b/packages/core/src/inner-plugins/plugins/ensureModulesChunkGraph.ts @@ -105,6 +105,7 @@ export const ensureModulesChunksGraphFn = ( ChunksBuildUtils.TileGraphReportName, ), reportTitle: 'bundle-analyzer', + reportDir: _this.options.reportDir, }, compiler.outputPath, );