@@ -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.
@@ -206,7 +209,13 @@ function esbuildTask(entrypoint, outfile, exportIsTsObject = false) {
206
209
207
210
// TODO: these need to have better function names, for gulp.
208
211
return {
209
- build : ( ) => esbuild . build ( options ) ,
212
+ build : async ( ) => {
213
+ await esbuild . build ( options ) ;
214
+ if ( performanceMatters ) {
215
+ 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" ] ) ;
216
+ await del ( [ preBabel , `${ preBabel } .map` ] ) ;
217
+ }
218
+ } ,
210
219
clean : ( ) => del ( [ outfile , `${ outfile } .map` ] ) ,
211
220
watch : ( ) => esbuild . build ( { ...options , watch : true } ) ,
212
221
} ;
@@ -238,7 +247,7 @@ cleanTasks.push(cleanDebugTools);
238
247
const lkgPreBuild = parallel ( generateLibs , series ( buildScripts , generateDiagnostics , buildDebugTools ) ) ;
239
248
240
249
241
- const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true ) ;
250
+ const esbuildTsc = esbuildTask ( "./src/tsc/tsc.ts" , "./built/local/tsc.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
242
251
243
252
244
253
const buildTsc = ( ) => cmdLineOptions . bundle ? esbuildTsc . build ( ) : buildProject ( "src/tsc" ) ;
@@ -260,7 +269,7 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
260
269
// Pre-build steps to use based on supplied options.
261
270
const preBuild = cmdLineOptions . lkg ? lkgPreBuild : localPreBuild ;
262
271
263
- const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true ) ;
272
+ const esbuildServices = esbuildTask ( "./src/typescript/typescript.ts" , "./built/local/typescript.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
264
273
265
274
const buildServices = ( ) => cmdLineOptions . bundle ? esbuildServices . build ( ) : buildProject ( "src/typescript" ) ;
266
275
@@ -285,7 +294,7 @@ task("watch-services").flags = {
285
294
} ;
286
295
287
296
288
- const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true ) ;
297
+ const esbuildServer = esbuildTask ( "./src/tsserver/server.ts" , "./built/local/tsserver.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
289
298
290
299
const buildServer = ( ) => cmdLineOptions . bundle ? esbuildServer . build ( ) : buildProject ( "src/tsserver" ) ;
291
300
buildServer . displayName = "buildServer" ;
@@ -323,7 +332,7 @@ task("watch-min").flags = {
323
332
" --built" : "Compile using the built version of the compiler."
324
333
} ;
325
334
326
- const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true ) ;
335
+ const esbuildLssl = esbuildTask ( "./src/tsserverlibrary/tsserverlibrary.ts" , "./built/local/tsserverlibrary.js" , /* exportIsTsObject */ true , /* performanceMatters */ true ) ;
327
336
328
337
const buildLssl = ( ) => cmdLineOptions . bundle ? esbuildLssl . build ( ) : buildProject ( "src/tsserverlibrary" ) ;
329
338
task ( "lssl" , series ( preBuild , buildLssl ) ) ;
0 commit comments