Files
payloadcms/packages/payload/bundle.js
Alessio Gravili af9837de44 ci: analyze bundle size (#13071)
This adds a new `analyze` step to our CI that analyzes the bundle size
for our `payload`, `@payloadcms/ui`, `@payloadcms/next` and
`@payloadcms/richtext-lexical` packages.

It does so using a new `build:bundle-for-analysis` script that packages
can add if the normal build step does not output an esbuild-bundled
version suitable for analyzing. For example, `ui` already runs esbuild,
but we run it again using `build:bundle-for-analysis` because we do not
want to split the bundle.

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210692087147570
2025-07-07 20:00:02 +00:00

69 lines
1.6 KiB
JavaScript

import * as esbuild from 'esbuild'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
const directoryArg = process.argv[2] || 'dist'
async function build() {
const resultIndex = await esbuild.build({
entryPoints: ['dist/index.js'],
bundle: true,
platform: 'node',
format: 'esm',
outfile: `${directoryArg}/index.js`,
splitting: false,
external: [
'lodash',
'*.scss',
'*.css',
'@payloadcms/translations',
'memoizee',
'pino-pretty',
'pino',
//'ajv',
//'image-size',
],
minify: true,
metafile: true,
tsconfig: path.resolve(dirname, './tsconfig.json'),
// plugins: [commonjs()],
sourcemap: true,
})
console.log('payload server bundled successfully')
const resultShared = await esbuild.build({
entryPoints: ['dist/exports/shared.js'],
bundle: true,
platform: 'node',
format: 'esm',
outfile: `${directoryArg}/exports/shared.js`,
splitting: false,
external: [
'lodash',
'*.scss',
'*.css',
'@payloadcms/translations',
'memoizee',
'pino-pretty',
'pino',
//'ajv',
//'image-size',
],
minify: true,
metafile: true,
tsconfig: path.resolve(dirname, './tsconfig.json'),
// plugins: [commonjs()],
sourcemap: true,
})
console.log('payload shared bundled successfully')
fs.writeFileSync('meta_index.json', JSON.stringify(resultIndex.metafile))
fs.writeFileSync('meta_shared.json', JSON.stringify(resultShared.metafile))
}
await build()