@@ -162,14 +162,17 @@ function getCopyrightHeader() {
162
162
* @param {string } entrypoint
163
163
* @param {string } outfile
164
164
* @param {boolean } exportIsTsObject True if this file exports the TS object and should have relevant code injected.
165
+ * @param {boolean } performanceMatters True if this is a bundle where performance matters, so should be optimized at the cost of build time.
165
166
*/
166
- function esbuildTask ( entrypoint , outfile , exportIsTsObject = false ) {
167
+ function esbuildTask ( entrypoint , outfile , exportIsTsObject = false , performanceMatters = false ) {
168
+ const preBabel = `${ outfile } .tmp.js` ;
169
+
167
170
/** @type {esbuild.BuildOptions } */
168
171
const options = {
169
172
entryPoints : [ entrypoint ] ,
170
173
banner : { js : getCopyrightHeader ( ) } ,
171
174
bundle : true ,
172
- outfile,
175
+ outfile : performanceMatters ? preBabel : outfile ,
173
176
platform : "node" ,
174
177
// TODO: also specify minimal browser targets
175
178
target : "node10" , // Node 10 is the oldest benchmarker.
@@ -205,7 +208,13 @@ function esbuildTask(entrypoint, outfile, exportIsTsObject = false) {
205
208
}
206
209
207
210
return {
208
- build : ( ) => esbuild . build ( options ) ,
211
+ build : async ( ) => {
212
+ await esbuild . build ( options ) ;
213
+ if ( performanceMatters ) {
214
+ 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" ] ) ;
215
+ await del ( [ preBabel , `${ preBabel } .map` ] ) ;
216
+ }
217
+ } ,
209
218
clean : ( ) => del ( [ outfile , `${ outfile } .map` ] ) ,
210
219
watch : ( ) => esbuild . build ( { ...options , watch : true } ) ,
211
220
} ;
@@ -237,7 +246,7 @@ cleanTasks.push(cleanDebugTools);
237
246
const lkgPreBuild = parallel ( generateLibs , series ( buildScripts , generateDiagnostics , buildDebugTools ) ) ;
238
247
239
248
240
- const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true ) ;
249
+ const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
241
250
242
251
243
252
const buildTsc = ( ) => cmdLineOptions . bundle ? esbuildTsc . build ( ) : buildProject ( "src/tsc" ) ;
@@ -259,7 +268,7 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
259
268
// Pre-build steps to use based on supplied options.
260
269
const preBuild = cmdLineOptions . lkg ? lkgPreBuild : localPreBuild ;
261
270
262
- const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true ) ;
271
+ const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
263
272
264
273
const buildServices = ( ) => cmdLineOptions . bundle ? esbuildServices . build ( ) : buildProject ( "src/typescript" ) ;
265
274
@@ -284,7 +293,7 @@ task("watch-services").flags = {
284
293
} ;
285
294
286
295
287
- const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true ) ;
296
+ const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
288
297
289
298
const buildServer = ( ) => cmdLineOptions . bundle ? esbuildServer . build ( ) : buildProject ( "src/tsserver" ) ;
290
299
buildServer . displayName = "buildServer" ;
@@ -322,7 +331,7 @@ task("watch-min").flags = {
322
331
" --built" : "Compile using the built version of the compiler."
323
332
} ;
324
333
325
- const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true ) ;
334
+ const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
326
335
327
336
const buildLssl = ( ) => cmdLineOptions . bundle ? esbuildLssl . build ( ) : buildProject ( "src/tsserverlibrary" ) ;
328
337
task ( "lssl" , series ( preBuild , buildLssl ) ) ;
0 commit comments