@@ -10,6 +10,7 @@ const { minify } = require('terser');
10
10
const zlib = require ( 'node:zlib' ) ;
11
11
const { init : initEsmLexer , parse } = require ( 'es-module-lexer' ) ;
12
12
const MagicString = require ( 'magic-string' ) ;
13
+ const { platform } = require ( 'node:os' ) ;
13
14
14
15
/**
15
16
* Transform ESM to CJS using destructured imports
@@ -223,18 +224,28 @@ async function main() {
223
224
compress : {
224
225
...mangleConfig . minify . compress ,
225
226
pure_getters : true ,
227
+ // For some reason this is needed else
228
+ // the var declarations will come before
229
+ // the imports
226
230
hoist_vars : false ,
227
- hoist_funs : false ,
231
+ inline : 3 ,
232
+ sequences : 100 ,
228
233
keep_infinity : true ,
234
+ reduce_vars : true ,
235
+ reduce_funcs : false ,
236
+ collapse_vars : true ,
237
+ side_effects : true ,
229
238
unsafe_proto : true ,
230
239
passes : 10 ,
231
- toplevel : true
240
+ ecma : 2020 ,
241
+ module : true
232
242
} ,
233
243
mangle : {
234
- toplevel : true ,
235
244
properties : { ...mangleConfig . minify . mangle . properties , reserved }
236
245
} ,
237
246
format : {
247
+ ascii_only : true ,
248
+ wrap_iife : false ,
238
249
shorthand : true ,
239
250
wrap_func_args : false ,
240
251
comments : / ^ \s * ( [ @ # ] _ _ [ A - Z ] + _ _ \s * $ | @ c c _ o n ) / ,
@@ -292,12 +303,15 @@ async function main() {
292
303
bundle : true ,
293
304
sourcemap : true ,
294
305
sourcesContent : true ,
306
+ treeShaking : true ,
307
+ platform : 'browser' ,
308
+ jsxSideEffects : false ,
295
309
plugins : [ babelRenamePlugin ( ) ] ,
296
310
target : [ 'es2020' ] ,
297
311
define : { 'process.env.NODE_ENV' : '"production"' }
298
312
} ;
299
313
300
- // Build ESM first
314
+ // @ts -expect-error
301
315
await build ( {
302
316
...shared ,
303
317
format : 'esm' ,
@@ -333,7 +347,7 @@ async function main() {
333
347
params : { [ zlib . constants . BROTLI_PARAM_QUALITY ] : 11 }
334
348
} ) . length ;
335
349
sizeRows . push ( {
336
- pkg : pkg . id ,
350
+ pkg : pkg . id + ( ext === '.mjs' ? ' (esm)' : '(cjs)' ) ,
337
351
file : path . relative ( root , abs ) ,
338
352
raw,
339
353
gz,
@@ -343,9 +357,26 @@ async function main() {
343
357
}
344
358
345
359
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' ) ) ;
360
+
361
+ const headers = [ 'Package' , 'Raw' , 'Gzip' , 'Brotli' ] ;
362
+ const rows = sizeRows . map ( r => [
363
+ r . pkg ,
364
+ String ( r . raw ) ,
365
+ String ( r . gz ) ,
366
+ String ( r . br )
367
+ ] ) ;
368
+ const colWidths = headers . map ( ( h , i ) =>
369
+ Math . max ( h . length , ...rows . map ( r => r [ i ] . length ) )
370
+ ) ;
371
+
372
+ function pad ( v , i ) {
373
+ const w = colWidths [ i ] ;
374
+ return v + ' ' . repeat ( w - v . length ) ;
375
+ }
376
+
377
+ console . log ( headers . map ( pad ) . join ( ' ' ) ) ;
378
+ for ( const r of rows ) {
379
+ console . log ( r . map ( pad ) . join ( ' ' ) ) ;
349
380
}
350
381
console . log ( '\nDone.' ) ;
351
382
}
0 commit comments