From b2e6777c81adbc00a2e6abcc7491eea38496635d Mon Sep 17 00:00:00 2001 From: Katia <129207373+katia-sentry@users.noreply.github.com> Date: Thu, 10 Jul 2025 06:18:15 -0400 Subject: [PATCH] =?UTF-8?q?=20=F0=9F=94=A8=20chore:=20Add=20Codecov=20Bund?= =?UTF-8?q?le=20Analysis=20(#6698)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Codecov Bundle Analysis integration - Add @codecov/webpack-plugin for bundle size tracking - Configure bundle analysis settings in codecov.yml - Update CI workflow to include bundle analysis step - Set bundle change threshold to 10KB * Use nextjs-webpack-plugin * Seperate workflow Move the Build with Bundle Analysis step to its own GitHub Actions workflow file. * Revert line additon change --------- Co-authored-by: katia-sentry --- .github/workflows/bundle-analysis.yml | 22 ++++++++++++++++++++++ codecov.yml | 8 ++++++++ next.config.ts | 13 +++++++++++++ package.json | 1 + 4 files changed, 44 insertions(+) create mode 100644 .github/workflows/bundle-analysis.yml diff --git a/.github/workflows/bundle-analysis.yml b/.github/workflows/bundle-analysis.yml new file mode 100644 index 0000000000..f771eaf9ca --- /dev/null +++ b/.github/workflows/bundle-analysis.yml @@ -0,0 +1,22 @@ +name: Bundle Analysis + +on: [push, pull_request] + +jobs: + analyze: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: ${{ secrets.BUN_VERSION }} + + - name: Install deps + run: bun i + + - name: Build with Bundle Analysis + run: bun run build:analyze + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/codecov.yml b/codecov.yml index 5fb59f6206..578f055159 100644 --- a/codecov.yml +++ b/codecov.yml @@ -9,3 +9,11 @@ coverage: flags: - app patch: off + +comment: + layout: "bundle" + require_changes: true + require_base: true + require_head: true + require_bundle_changes: true + bundle_change_threshold: "10Kb" diff --git a/next.config.ts b/next.config.ts index 852a94dc46..bac4e8cd13 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,5 +1,6 @@ import analyzer from '@next/bundle-analyzer'; import { withSentryConfig } from '@sentry/nextjs'; +import { codecovNextJSWebpackPlugin } from '@codecov/nextjs-webpack-plugin'; import withSerwistInit from '@serwist/next'; import type { NextConfig } from 'next'; import ReactComponentName from 'react-scan/react-component-name/webpack'; @@ -256,6 +257,18 @@ const nextConfig: NextConfig = { layers: true, }; + // Add Codecov webpack plugin + if (process.env.CODECOV_TOKEN) { + config.plugins.push( + codecovNextJSWebpackPlugin({ + enableBundleAnalysis: true, + bundleName: 'lobechat-bundle', + uploadToken: process.env.CODECOV_TOKEN, + webpack: config, + }), + ); + } + // 开启该插件会导致 pglite 的 fs bundler 被改表 if (enableReactScan && !isUsePglite) { config.plugins.push(ReactComponentName({})); diff --git a/package.json b/package.json index 558781059b..a719bde770 100644 --- a/package.json +++ b/package.json @@ -278,6 +278,7 @@ "zustand-utils": "^2.1.0" }, "devDependencies": { + "@codecov/nextjs-webpack-plugin": "^1.9.0", "@commitlint/cli": "^19.8.1", "@edge-runtime/vm": "^5.0.0", "@huggingface/tasks": "^0.15.9",