'use strict'; var extractStats = require('rollup-plugin-stats/extract'); var transform = require('./chunks/transform.cjs'); var path = require('node:path'); var fs = require('node:fs/promises'); require('path'); require('node:crypto'); async function statsWrite(filepath, stats) { const content = JSON.stringify(stats, null, 2); // Create base directory if it does not exist await fs.mkdir(path.dirname(filepath), { recursive: true }); await fs.writeFile(filepath, content); return { filepath, content, }; } const PLUGIN_NAME = 'webpackStats'; const webpackStats = (options = {}) => ({ name: PLUGIN_NAME, async generateBundle(outputOptions, bundle) { const resolvedOptions = typeof options === 'function' ? options(outputOptions) : options; const { fileName, excludeAssets, excludeModules, write = statsWrite, ...transformOptions } = resolvedOptions; const rollupStats = extractStats(bundle, { excludeAssets, excludeModules, // Extract stats source to compute size source: true, }); const stats = transform.bundleToWebpackStats(rollupStats, transformOptions); const filepath = transform.resolveFilepath(fileName, outputOptions.dir); try { const res = await write(filepath, stats); const outputSize = Buffer.byteLength(res.content, 'utf-8'); this.info(`Stats saved to ${res.filepath} (${transform.formatFileSize(outputSize)})`); } catch (error) { // eslint-disable-line // Log error, but do not throw to allow the compilation to continue this.warn(error); } }, }); module.exports = webpackStats; //# sourceMappingURL=index.cjs.map