// 스프레드시트 크기 재기 — vite 로 줄여 묶은 뒤 gzip 크기(바이트). `test_spreadsheet_size.py` 가 부름. // node spreadsheet_size.mjs <저장소 뿌리> → {"engine": {js, css}, "total": {js, css}} // 앱 번들에 이미 있는 `@ui/ui_template_elements*` 는 빼고 잼(스프레드시트가 새로 더하는 몫만). import path from "node:path"; import { pathToFileURL } from "node:url"; import { gzipSync } from "node:zlib"; const root = path.resolve(process.argv[2] ?? "."); const dir = path.join(root, "A00_Common", "spreadsheet"); const { build } = await import( pathToFileURL(path.join(root, "config/node_modules/vite/dist/node/index.js")).href ); const ENGINE = [ "spreadsheet_address", "spreadsheet_parser", "spreadsheet_eval", "spreadsheet_graph", "spreadsheet_refshift", "spreadsheet_commands", "spreadsheet_history", "spreadsheet_recalc", "spreadsheet_functions", "spreadsheet_numfmt", "spreadsheet_fill", ]; async function measure(entries) { const out = await build({ configFile: false, logLevel: "silent", root, resolve: { alias: { "@ui": path.join(root, "ui_template") } }, build: { write: false, minify: true, target: "es2022", cssCodeSplit: false, lib: { entry: entries, formats: ["es"] }, rollupOptions: { external: [/ui_template_elements/] }, }, }); const outputs = (Array.isArray(out) ? out : [out]).flatMap((o) => o.output); const size = { js: 0, css: 0 }; for (const o of outputs) { const body = o.type === "chunk" ? o.code : o.source; const gz = gzipSync(typeof body === "string" ? body : Buffer.from(body)).length; if (o.fileName.endsWith(".css")) size.css += gz; else if (o.fileName.endsWith(".js")) size.js += gz; } return size; } const engine = await measure(ENGINE.map((name) => path.join(dir, `${name}.ts`))); const total = await measure([path.join(dir, "spreadsheet.ts")]); console.log(JSON.stringify({ engine, total }));