Skip to content

Commit 2f77355

Browse files
committed
Some tweaks
1 parent d63a37f commit 2f77355

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

scripts/build-packages.cjs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { minify } = require('terser');
1010
const zlib = require('node:zlib');
1111
const { init: initEsmLexer, parse } = require('es-module-lexer');
1212
const MagicString = require('magic-string');
13+
const { platform } = require('node:os');
1314

1415
/**
1516
* Transform ESM to CJS using destructured imports
@@ -223,15 +224,15 @@ async function main() {
223224
compress: {
224225
...mangleConfig.minify.compress,
225226
pure_getters: true,
226-
hoist_vars: false,
227-
hoist_funs: false,
227+
// For some reason this is needed else
228+
// the var declarations will come before
229+
// the imports
230+
hoist_vars: true,
228231
keep_infinity: true,
229232
unsafe_proto: true,
230-
passes: 10,
231-
toplevel: true
233+
passes: 10
232234
},
233235
mangle: {
234-
toplevel: true,
235236
properties: { ...mangleConfig.minify.mangle.properties, reserved }
236237
},
237238
format: {
@@ -292,12 +293,15 @@ async function main() {
292293
bundle: true,
293294
sourcemap: true,
294295
sourcesContent: true,
296+
treeShaking: true,
297+
platform: 'browser',
298+
jsxSideEffects: false,
295299
plugins: [babelRenamePlugin()],
296300
target: ['es2020'],
297301
define: { 'process.env.NODE_ENV': '"production"' }
298302
};
299303

300-
// Build ESM first
304+
// @ts-expect-error
301305
await build({
302306
...shared,
303307
format: 'esm',
@@ -333,7 +337,7 @@ async function main() {
333337
params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 11 }
334338
}).length;
335339
sizeRows.push({
336-
pkg: pkg.id,
340+
pkg: pkg.id + (ext === '.mjs' ? ' (esm)' : '(cjs)'),
337341
file: path.relative(root, abs),
338342
raw,
339343
gz,
@@ -343,9 +347,26 @@ async function main() {
343347
}
344348

345349
console.log('\n[build] Artifact sizes (bytes):');
346-
console.log(['Package', 'File', 'Raw', 'Gzip', 'Brotli'].join('\t'));
347-
for (const row of sizeRows) {
348-
console.log([row.pkg, row.file, row.raw, row.gz, row.br].join('\t'));
350+
351+
const headers = ['Package', 'Raw', 'Gzip', 'Brotli'];
352+
const rows = sizeRows.map(r => [
353+
r.pkg,
354+
String(r.raw),
355+
String(r.gz),
356+
String(r.br)
357+
]);
358+
const colWidths = headers.map((h, i) =>
359+
Math.max(h.length, ...rows.map(r => r[i].length))
360+
);
361+
362+
function pad(v, i) {
363+
const w = colWidths[i];
364+
return v + ' '.repeat(w - v.length);
365+
}
366+
367+
console.log(headers.map(pad).join(' '));
368+
for (const r of rows) {
369+
console.log(r.map(pad).join(' '));
349370
}
350371
console.log('\nDone.');
351372
}

0 commit comments

Comments
 (0)