@lynx-js/rspeedy
Version:
A webpack/rspack-based frontend toolchain for Lynx
27 lines (26 loc) • 845 B
JavaScript
import { mkdir, writeFile } from "node:fs/promises";
import node_path from "node:path";
const BUNDLE_STATS_JSON_OPTIONS = {
assets: true,
chunks: true,
modules: true,
entrypoints: true,
chunkGroups: true
};
function pluginStatsJson(config) {
return {
name: 'lynx:stats-json',
setup (api) {
if (!config.performance?.profile) return;
api.onAfterBuild(async ({ stats })=>{
if (!stats) return;
const statsPath = node_path.join(api.context.distPath, 'stats.json');
await mkdir(node_path.dirname(statsPath), {
recursive: true
});
await writeFile(statsPath, JSON.stringify(stats.toJson(BUNDLE_STATS_JSON_OPTIONS), null, 2));
});
}
};
}
export { pluginStatsJson };