From e12f97b1d82b122b29e2fa63f7851b7e0d39b9ea Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Wed, 24 Jun 2026 15:01:37 +0900 Subject: [PATCH] enhance(dev): improve Frontend Bundle Report --- .github/scripts/frontend-js-size.mjs | 9 +++++ .github/workflows/frontend-bundle-report.yml | 17 +++++++-- packages/frontend/vite.config.ts | 38 ++++++++++---------- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/.github/scripts/frontend-js-size.mjs b/.github/scripts/frontend-js-size.mjs index cae5b769ed..e9c985b652 100644 --- a/.github/scripts/frontend-js-size.mjs +++ b/.github/scripts/frontend-js-size.mjs @@ -530,6 +530,13 @@ function renderFrontendBundleReport(before, after) { return lines.join('\n'); } +function renderVisualizerArtifactLink() { + const artifactUrl = process.env.FRONTEND_BUNDLE_REPORT_ARTIFACT_URL; + const artifactName = process.env.FRONTEND_BUNDLE_REPORT_ARTIFACT_NAME || 'frontend-bundle-report'; + const htmlFile = process.env.FRONTEND_BUNDLE_REPORT_HTML_FILE || 'frontend-bundle-visualizer.html'; + return `> [Bundle visualizer HTML](${artifactUrl}) is included in the ${code(artifactName)} artifact as ${code(htmlFile)}.`; +} + const args = process.argv.slice(2); const [beforeDir, afterDir, beforeStatsFile, afterStatsFile, outFile] = args; const before = await collectReport(beforeDir); @@ -547,6 +554,8 @@ const body = [ '## Bundle Stats', '', renderFrontendBundleReport(collectVisualizerReport(beforeStats), collectVisualizerReport(afterStats)), + '', + renderVisualizerArtifactLink(), ].join('\n'); await fs.writeFile(outFile, body); diff --git a/.github/workflows/frontend-bundle-report.yml b/.github/workflows/frontend-bundle-report.yml index e040bc390f..eb6c64e5f7 100644 --- a/.github/workflows/frontend-bundle-report.yml +++ b/.github/workflows/frontend-bundle-report.yml @@ -101,7 +101,6 @@ jobs: working-directory: before env: FRONTEND_BUNDLE_VISUALIZER: 'true' - FRONTEND_BUNDLE_VISUALIZER_TEMPLATE: raw-data FRONTEND_BUNDLE_VISUALIZER_FILE: ${{ runner.temp }}/frontend-bundle-report/before-stats.json run: pnpm --filter frontend run build @@ -120,10 +119,20 @@ jobs: working-directory: after env: FRONTEND_BUNDLE_VISUALIZER: 'true' - FRONTEND_BUNDLE_VISUALIZER_TEMPLATE: raw-data FRONTEND_BUNDLE_VISUALIZER_FILE: ${{ runner.temp }}/frontend-bundle-report/after-stats.json + FRONTEND_BUNDLE_VISUALIZER_HTML_FILE: ${{ runner.temp }}/frontend-bundle-report/frontend-bundle-visualizer.html run: pnpm --filter frontend run build + - name: Upload bundle visualizer + if: steps.check-base-visualizer.outputs.supported == 'true' + id: upload-bundle-visualizer + uses: actions/upload-artifact@v7 + with: + name: frontend-bundle-visualizer + path: ${{ runner.temp }}/frontend-bundle-report/frontend-bundle-visualizer.html + if-no-files-found: error + retention-days: 7 + - name: Generate report markdown if: steps.check-base-visualizer.outputs.supported == 'true' shell: bash @@ -131,6 +140,9 @@ jobs: BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_NUMBER: ${{ github.event.pull_request.number }} + FRONTEND_BUNDLE_REPORT_ARTIFACT_URL: ${{ steps.upload-bundle-visualizer.outputs.artifact-url }} + FRONTEND_BUNDLE_REPORT_ARTIFACT_NAME: frontend-bundle-visualizer + FRONTEND_BUNDLE_REPORT_HTML_FILE: frontend-bundle-visualizer.html run: | REPORT_DIR="$RUNNER_TEMP/frontend-bundle-report" node after/.github/scripts/frontend-js-size.mjs before after "$REPORT_DIR/before-stats.json" "$REPORT_DIR/after-stats.json" "$REPORT_DIR/frontend-js-size-report.md" @@ -145,6 +157,7 @@ jobs: REPORT_DIR="$RUNNER_TEMP/frontend-bundle-report" test -s "$REPORT_DIR/before-stats.json" test -s "$REPORT_DIR/after-stats.json" + test -s "$REPORT_DIR/frontend-bundle-visualizer.html" test -s "$REPORT_DIR/frontend-js-size-report.md" cat "$REPORT_DIR/frontend-js-size-report.md" >> "$GITHUB_STEP_SUMMARY" diff --git a/packages/frontend/vite.config.ts b/packages/frontend/vite.config.ts index b1413be0a4..8cf725b1a1 100644 --- a/packages/frontend/vite.config.ts +++ b/packages/frontend/vite.config.ts @@ -27,27 +27,29 @@ const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.s function getBundleVisualizerPlugin(): PluginOption[] { if (process.env.FRONTEND_BUNDLE_VISUALIZER !== 'true') return []; - const template = process.env.FRONTEND_BUNDLE_VISUALIZER_TEMPLATE === 'markdown' - ? 'markdown' - : process.env.FRONTEND_BUNDLE_VISUALIZER_TEMPLATE === 'raw-data' - ? 'raw-data' - : 'treemap'; - const defaultFilename = template === 'markdown' - ? path.resolve(__dirname, '../../built/_frontend_bundle_visualizer_/report.md') - : template === 'raw-data' - ? path.resolve(__dirname, '../../built/_frontend_bundle_visualizer_/stats.json') - : path.resolve(__dirname, '../../built/_frontend_bundle_visualizer_/stats.html'); - - return [ + const visualizerOptions = { + title: 'Misskey frontend bundle visualizer', + gzipSize: true, + brotliSize: true, + projectRoot: path.resolve(__dirname, '../..'), + }; + const plugins = [ visualizer({ - filename: process.env.FRONTEND_BUNDLE_VISUALIZER_FILE ?? defaultFilename, - title: 'Misskey frontend bundle visualizer', - template, - gzipSize: true, - brotliSize: true, - projectRoot: path.resolve(__dirname, '../..'), + ...visualizerOptions, + filename: process.env.FRONTEND_BUNDLE_VISUALIZER_FILE, + template: 'raw-data', }) as PluginOption, ]; + + if (process.env.FRONTEND_BUNDLE_VISUALIZER_HTML_FILE != null) { + plugins.push(visualizer({ + ...visualizerOptions, + filename: process.env.FRONTEND_BUNDLE_VISUALIZER_HTML_FILE, + template: 'treemap', + }) as PluginOption); + } + + return plugins; } /**