@@ -140,14 +140,17 @@ function getCopyrightHeader() {
140
140
* @param {string } entrypoint
141
141
* @param {string } outfile
142
142
* @param {boolean } exportIsTsObject True if this file exports the TS object and should have relevant code injected.
143
+ * @param {boolean } performanceMatters True if this is a bundle where performance matters, so should be optimized at the cost of build time.
143
144
*/
144
- function esbuildTask ( entrypoint , outfile , exportIsTsObject = false ) {
145
+ function esbuildTask ( entrypoint , outfile , exportIsTsObject = false , performanceMatters = false ) {
146
+ const preBabel = `${ outfile } .tmp.js` ;
147
+
145
148
/** @type {esbuild.BuildOptions } */
146
149
const options = {
147
150
entryPoints : [ entrypoint ] ,
148
151
banner : { js : getCopyrightHeader ( ) } ,
149
152
bundle : true ,
150
- outfile,
153
+ outfile : performanceMatters ? preBabel : outfile ,
151
154
platform : "node" ,
152
155
// TODO: also specify minimal browser targets
153
156
target : "node10" , // Node 10 is the oldest benchmarker.
@@ -183,7 +186,14 @@ function esbuildTask(entrypoint, outfile, exportIsTsObject = false) {
183
186
}
184
187
185
188
return {
186
- build : ( ) => esbuild . build ( options ) ,
189
+ build : async ( ) => {
190
+ await esbuild . build ( options ) ;
191
+ if ( performanceMatters ) {
192
+ // TODO: we could use ts.transpileModule for this, but running babel is faster to get this singular transform.
193
+ await exec ( process . execPath , [ "./node_modules/@babel/cli/bin/babel.js" , preBabel , "--out-file" , outfile , "--plugins" , "@babel/plugin-transform-block-scoping" , "--compact" , "false" , "--source-maps" ] ) ;
194
+ await del ( [ preBabel , `${ preBabel } .map` ] ) ;
195
+ }
196
+ } ,
187
197
clean : ( ) => del ( [ outfile , `${ outfile } .map` ] ) ,
188
198
watch : ( ) => esbuild . build ( { ...options , watch : true } ) ,
189
199
} ;
@@ -211,7 +221,7 @@ cleanTasks.push(cleanDebugTools);
211
221
const lkgPreBuild = parallel ( generateLibs , series ( buildScripts , generateDiagnostics , buildDebugTools ) ) ;
212
222
213
223
214
- const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true ) ;
224
+ const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
215
225
216
226
217
227
const buildTsc = ( ) => {
@@ -238,7 +248,7 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
238
248
// Pre-build steps to use based on supplied options.
239
249
const preBuild = cmdLineOptions . lkg ? lkgPreBuild : localPreBuild ;
240
250
241
- const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true ) ;
251
+ const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
242
252
243
253
// TODO(jakebailey): rename this; no longer "services".
244
254
const buildServices = ( ) => {
@@ -268,7 +278,7 @@ task("watch-services").flags = {
268
278
} ;
269
279
270
280
271
- const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true ) ;
281
+ const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
272
282
273
283
const buildServer = ( ) => {
274
284
if ( cmdLineOptions . bundle ) return esbuildServer . build ( ) ;
@@ -311,7 +321,7 @@ task("watch-min").flags = {
311
321
" --built" : "Compile using the built version of the compiler."
312
322
} ;
313
323
314
- const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true ) ;
324
+ const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
315
325
316
326
const buildLssl = ( ) => {
317
327
if ( cmdLineOptions . bundle ) return esbuildLssl . build ( ) ;
0 commit comments