Skip to content

Commit

Permalink
chore: add bundle analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Dec 10, 2024
1 parent de3bedf commit 6c139f6
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ jobs:
- name: Build
run: pnpm build

- name: Analyze build
env:
BUNDLE_ANALYZER_UPLOAD_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
run: pnpm build:analyze

- name: Cache build output
uses: actions/cache@v4
with:
Expand Down
27 changes: 27 additions & 0 deletions analyze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { createAndUploadReport } = require('@codecov/bundle-analyzer')

const buildDirs = ['/absolute/or/relative/path/to/build']

const coreOpts = {
dryRun: true,
uploadToken: 'your-upload-token',
retryCount: 3,
apiUrl: 'https://api.codecov.io',
bundleName: '@codecov/example-bundle-analyzer-cjs',
enableBundleAnalysis: true,
debug: true,
}

const bundleAnalyzerOpts = {
beforeReportUpload: async (original) => original,
ignorePatterns: ['*.map'],
normalizeAssetsPattern: '[name]-[hash].js',
}

createAndUploadReport(buildDirs, coreOpts, bundleAnalyzerOpts)
.then((reportAsJson) =>
console.log(`Report successfully generated and uploaded: ${reportAsJson}`),
)
.catch((error) =>
console.error('Failed to generate or upload report:', error),
)
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"clean": "rimraf ./lib",
"lint": "eslint \"{cli,src}/**/*.ts\"",
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
"build:analyze": "node analyze.js",
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
"check:exports": "node \"./config/scripts/validate-esm.js\"",
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
Expand Down Expand Up @@ -159,6 +160,7 @@
"yargs": "^17.7.2"
},
"devDependencies": {
"@codecov/bundle-analyzer": "^1.6.0",
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@fastify/websocket": "^8.3.1",
Expand Down
Loading

0 comments on commit 6c139f6

Please sign in to comment.