🔨 chore: Add Codecov Bundle Analysis (#6698)

* 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 <katia.al-amir@sentry.com>
This commit is contained in:
Katia
2025-07-10 06:18:15 -04:00
committed by GitHub
parent afd59004f9
commit b2e6777c81
4 changed files with 44 additions and 0 deletions

22
.github/workflows/bundle-analysis.yml vendored Normal file
View File

@@ -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 }}

View File

@@ -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"

View File

@@ -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({}));

View File

@@ -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",