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
33 lines
975 B
JavaScript
33 lines
975 B
JavaScript
import * as esbuild from 'esbuild'
|
|
import fs from 'fs'
|
|
import { sassPlugin } from 'esbuild-sass-plugin'
|
|
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/esbuildEntry.js'],
|
|
bundle: true,
|
|
platform: 'node',
|
|
format: 'esm',
|
|
outfile: `${directoryArg}/index.js`,
|
|
splitting: false,
|
|
external: ['@payloadcms/ui', 'payload', '@payloadcms/translations', '@payloadcms/graphql'],
|
|
minify: true,
|
|
metafile: true,
|
|
tsconfig: path.resolve(dirname, './tsconfig.json'),
|
|
// plugins: [commonjs()],
|
|
sourcemap: true,
|
|
plugins: [sassPlugin({ css: 'external' })],
|
|
})
|
|
console.log('payload server bundled successfully')
|
|
|
|
fs.writeFileSync('meta_index.json', JSON.stringify(resultIndex.metafile))
|
|
}
|
|
|
|
await build()
|