diff --git a/src/build.ts b/src/build.ts index cc13394b8d..c79273518f 100644 --- a/src/build.ts +++ b/src/build.ts @@ -416,7 +416,9 @@ async function _build(nitro: Nitro, rollupConfig: RollupConfig) { nitro.logger.success("Nitro server built"); if (nitro.options.logLevel > 1) { process.stdout.write( - await generateFSTree(nitro.options.output.serverDir) + await generateFSTree(nitro.options.output.serverDir, { + compressedSizes: nitro.options.logging.compressedSizes, + }) ); } } diff --git a/src/options.ts b/src/options.ts index cb8572281f..7bb845b07a 100644 --- a/src/options.ts +++ b/src/options.ts @@ -69,6 +69,11 @@ const NitroDefaults: NitroConfig = { watchOptions: { ignoreInitial: true }, devProxy: {}, + // Logging + logging: { + compressedSizes: true, + }, + // Routing baseURL: process.env.NITRO_APP_BASE_URL || "/", handlers: [], diff --git a/src/types/nitro.ts b/src/types/nitro.ts index 24ff0d60cf..e398362e89 100644 --- a/src/types/nitro.ts +++ b/src/types/nitro.ts @@ -279,6 +279,11 @@ export interface NitroOptions extends PresetOptions { watchOptions: WatchOptions; devProxy: Record; + // Logging + logging: { + compressedSizes: boolean; + }; + // Routing baseURL: string; handlers: NitroEventHandler[]; diff --git a/src/utils/tree.ts b/src/utils/tree.ts index 69084dbed1..a2f3391e9d 100644 --- a/src/utils/tree.ts +++ b/src/utils/tree.ts @@ -6,7 +6,10 @@ import { gzipSize } from "gzip-size"; import chalk from "chalk"; import { isTest } from "std-env"; -export async function generateFSTree(dir: string) { +export async function generateFSTree( + dir: string, + options: { compressedSizes?: boolean } = {} +) { if (isTest) { return; } @@ -19,7 +22,7 @@ export async function generateFSTree(dir: string) { const path = resolve(dir, file); const src = await fsp.readFile(path); const size = src.byteLength; - const gzip = await gzipSize(src); + const gzip = options.compressedSizes ? await gzipSize(src) : 0; return { file, path, size, gzip }; }) ) @@ -50,17 +53,23 @@ export async function generateFSTree(dir: string) { } treeText += chalk.gray( - ` ${treeChar} ${rpath} (${prettyBytes(item.size)}) (${prettyBytes( - item.gzip - )} gzip)\n` + ` ${treeChar} ${rpath} (${prettyBytes(item.size)})` ); + if (options.compressedSizes) { + treeText += chalk.gray(` (${prettyBytes(item.gzip)} gzip)`); + } + treeText += "\n"; totalSize += item.size; totalGzip += item.gzip; } treeText += `${chalk.cyan("Σ Total size:")} ${prettyBytes( totalSize + totalNodeModulesSize - )} (${prettyBytes(totalGzip + totalNodeModulesGzip)} gzip)\n`; + )}`; + if (options.compressedSizes) { + treeText += ` (${prettyBytes(totalGzip + totalNodeModulesGzip)} gzip)`; + } + treeText += "\n"; return treeText; }