@@ -10,9 +10,12 @@ const logger = new Logger('build');
10
10
logger . info ( 'Building...' ) ;
11
11
12
12
function encodeBinary ( a : Buffer ) {
13
- const file = zlib . gzipSync ( a ) ;
13
+ const file = zlib . gzipSync ( a , { level : 9 } ) ;
14
14
return chunk ( [ ...encode ( file ) ] , 1000 ) . map ( ( i ) => String . fromCodePoint ( ...i ) ) . join ( '' ) ;
15
15
}
16
+ function size ( a : string ) {
17
+ return `${ Math . floor ( ( Buffer . from ( a ) . length / 1024 / 1024 ) * 10 ) / 10 } MB` ;
18
+ }
16
19
17
20
const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==' ;
18
21
@@ -28,14 +31,16 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
28
31
minify : true ,
29
32
entryPoints : [ path . resolve ( process . cwd ( ) , 'packages/server/index.ts' ) ] ,
30
33
charset : 'utf8' ,
31
- sourcemap : ' inline',
34
+ sourcemap : process . argv . includes ( '--debug' ) ? ' inline' : false ,
32
35
plugins : [ {
33
36
name : 'base16384' ,
34
37
setup ( b ) {
35
38
b . onLoad ( { filter : / \. ( f r o n t e n d | t t f | w a s m ) $ / , namespace : 'file' } , ( t ) => {
36
39
const file = fs . readFileSync ( path . join ( t . path ) ) ;
40
+ const contents = `module.exports = "${ encodeBinary ( file ) } ";\n${ nopMap } ` ;
41
+ console . log ( t . path , size ( contents ) ) ;
37
42
return {
38
- contents : `module.exports = " ${ encodeBinary ( file ) } ";\n ${ nopMap } ` ,
43
+ contents,
39
44
loader : 'tsx' ,
40
45
} ;
41
46
} ) ;
@@ -52,7 +57,7 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
52
57
} ) ;
53
58
if ( res . errors . length ) console . error ( res . errors ) ;
54
59
if ( res . warnings . length ) console . warn ( res . warnings ) ;
55
- logger . info ( `Resource Size: ${ Math . floor ( ( res . outputFiles [ 0 ] . text . length / 1024 / 1024 ) * 10 ) / 10 } MB ` ) ;
60
+ logger . info ( `Resource Size: ${ size ( res . outputFiles [ 0 ] . text ) } ` ) ;
56
61
fs . writeFileSync ( path . resolve ( process . cwd ( ) , 'dist/xcpc-tools.js' ) , res . outputFiles [ 0 ] . text ) ;
57
62
logger . info ( 'Saved to dist/xcpc-tools.js' ) ;
58
63
} ) ( ) ;
0 commit comments