improve meta file generation

This commit is contained in:
Norbert de Langen 2024-08-27 11:51:39 +02:00
parent d768c02b93
commit c8f7b670c0

View File

@ -309,25 +309,23 @@ async function run() {
});
} else {
await Promise.all(
compile.map(async (context) => {
compile.map(async (context, index) => {
const out = await context.rebuild();
await context.dispose();
/**
* I'm leaving this in place, because I want to start utilizing it in the future. I'm
* imagining a github action that shows the bundle analysis in the PR. I didn't have the
* project-scope to make that happen now, but I want expose this very rich useful data
* accessible, for the next person investigating bundle size issues.
*/
if (out.metafile) {
const { outputs } = out.metafile;
const keys = Object.keys(outputs);
const format = keys.every((key) => key.endsWith('.js')) ? 'esm' : 'cjs';
const outName =
keys.length === 1 ? dirname(keys[0]).replace('dist/', '') : `meta-${format}-${index}`;
await ensureDir('report');
await writeFile('report/meta.json', JSON.stringify(out.metafile, null, 2));
await writeFile(`report/${outName}.json`, JSON.stringify(out.metafile, null, 2));
await writeFile(
'report/meta.txt',
`report/${outName}.txt`,
await esbuild.analyzeMetafile(out.metafile, { color: false, verbose: false })
);
// console.log(await esbuild.analyzeMetafile(out.metafile, { color: true }));
}
})
);