mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-11 00:06:25 +08:00
improve meta file generation
This commit is contained in:
parent
d768c02b93
commit
c8f7b670c0
@ -309,25 +309,23 @@ async function run() {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
compile.map(async (context) => {
|
compile.map(async (context, index) => {
|
||||||
const out = await context.rebuild();
|
const out = await context.rebuild();
|
||||||
await context.dispose();
|
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) {
|
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 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(
|
await writeFile(
|
||||||
'report/meta.txt',
|
`report/${outName}.txt`,
|
||||||
await esbuild.analyzeMetafile(out.metafile, { color: false, verbose: false })
|
await esbuild.analyzeMetafile(out.metafile, { color: false, verbose: false })
|
||||||
);
|
);
|
||||||
// console.log(await esbuild.analyzeMetafile(out.metafile, { color: true }));
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user