Skip to content

Commit

Permalink
build: Switch to esbuild instead of rollup for the client and banner
Browse files Browse the repository at this point in the history
We have found that the performance with esbuild is much better than
using rollup and especially rollup+terser. This allows us to efficiently
build, minify, and treeshake the client code, especially with respect to
the new dependency on the typescript scanner for the client middleware.

We still need to investigate how or if we can use esbuild for the server
code as well. Since it does not support the 'amd' format, we need to see
if there is another way to configure it to generate the output we need
to use the `define` from the banner for requires.
  • Loading branch information
atscott committed Mar 10, 2021
1 parent 476dcb2 commit 27ccba8
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 42 deletions.
13 changes: 0 additions & 13 deletions banner.rollup.config.js

This file was deleted.

67 changes: 67 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const esbuild = require('esbuild');
const fs = require('fs');

const defaultOptions = {
bundle: true,
platform: 'node',
logLevel: 'info',
};

/** @type esbuild.BuildOptions */
const clientConfig = {
...defaultOptions,
entryPoints: ['dist/client/extension.js'],
outfile: 'dist/npm/index.js',
external: [
'fs',
'path',
'vscode',
'vscode-languageclient/node',
'vscode-languageserver-protocol',
'vscode-jsonrpc',
],
format: 'cjs',
minify: true,
};

/** @type esbuild.BuildOptions */
const bannerConfig = {
...defaultOptions,
entryPoints: ['dist/banner/banner.js'],
outfile: 'dist/banner/banner.esbuild.js',
external: [
'path',
],
format: 'cjs',
};

/** @type esbuild.BuildOptions */
const serverConfig = {
...defaultOptions,
entryPoints: ['dist/server/server.js'],
outfile: 'dist/npm/server/index.js',
external: [
'fs',
'path',
'typescript/lib/tsserverlibrary',
'vscode-languageserver',
'vscode-uri',
'vscode-jsonrpc',
],
// TODO(atscott): Figure out how to use the banner correctly.
// iife format produces a `require("typescript/lib/tsserverlibrary");` line but it needs to use
// the `define` in the banner to resolve tsserverlibrary.
format: 'iife',
};

async function build() {
try {
await esbuild.build(clientConfig);
await esbuild.build(bannerConfig);
} catch (e) {
console.error(e);
process.exit(1);
}
}

build();
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@
],
"main": "./dist/client/extension",
"scripts": {
"compile": "yarn compile:banner && tsc -b && rollup -c",
"compile:banner": "tsc -p server/banner.tsconfig.json && rollup -c banner.rollup.config.js",
"compile": "tsc -p server/banner.tsconfig.json && tsc -b && node esbuild.js && rollup -c",
"compile:test": "tsc -b server/src/tests",
"compile:integration": "tsc -b integration",
"compile:syntaxes-test": "tsc -b syntaxes/test",
Expand All @@ -163,6 +162,7 @@
"@types/jasmine": "3.6.3",
"@types/node": "12.19.16",
"clang-format": "1.5.0",
"esbuild": "^0.9.0",
"jasmine": "3.6.4",
"prettier": "2.2.1",
"rollup": "2.38.5",
Expand All @@ -178,4 +178,4 @@
"type": "git",
"url": "https://github.com/angular/vscode-ng-language-service"
}
}
}
20 changes: 2 additions & 18 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,12 @@ import * as fs from 'fs';
import commonjs from 'rollup-plugin-commonjs';

module.exports = [
{
input: 'dist/client/extension.js',
output: {
file: 'dist/npm/index.js',
format: 'cjs',
exports: 'named',
},
external: [
'path',
'vscode',
'vscode-languageclient',
],
plugins: [
commonjs(),
],
},
{
input: 'dist/server/server.js',
output: {
file: 'dist/npm/server/index.js',
format: 'amd',
banner: fs.readFileSync('dist/banner/banner.rollup.js', 'utf8'),
banner: fs.readFileSync('dist/banner/banner.esbuild.js', 'utf8'),
},
external: [
'fs',
Expand All @@ -41,4 +25,4 @@ module.exports = [
}),
],
},
];
];
29 changes: 21 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==

"@types/estree@*":
version "0.0.45"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.45.tgz#e9387572998e5ecdac221950dab3e8c3b16af884"
integrity sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g==
version "0.0.46"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.46.tgz#0fb6bfbbeabd7a30880504993369c4bf1deab1fe"
integrity sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg==

"@types/jasmine@3.6.3":
version "3.6.3"
Expand Down Expand Up @@ -331,6 +331,11 @@ es6-promisify@^5.0.0:
dependencies:
es6-promise "^4.0.3"

esbuild@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.9.0.tgz#b8320df85048ed1637c6b59ee52abba248936d3c"
integrity sha512-IqYFO7ZKHf0y4uJpJfGqInmSRn8jMPMbyI1W0Y2PSjSjJcVP538tC8TleJAS4Y8QeqwajqBTwFKayWVzYlMIgg==

escape-string-regexp@1.0.5, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
Expand Down Expand Up @@ -364,9 +369,9 @@ fs.realpath@^1.0.0:
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=

fsevents@~2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.1.tgz#b209ab14c61012636c8863507edf7fb68cc54e9f"
integrity sha512-YR47Eg4hChJGAB1O3yEAOkGO+rlzutoICGqGo9EZ4lKWokzZRSyIW1QmTzqjtw8MJdj9srP869CuWw/hyzSiBw==
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

function-bind@^1.1.1:
version "1.1.1"
Expand Down Expand Up @@ -477,7 +482,7 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==

is-core-module@^2.1.0:
is-core-module@^2.1.0, is-core-module@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a"
integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==
Expand Down Expand Up @@ -741,14 +746,22 @@ readable-stream@^3.1.1:
string_decoder "^1.1.1"
util-deprecate "^1.0.1"

resolve@^1.1.6, resolve@^1.11.0, resolve@^1.3.2:
resolve@^1.1.6, resolve@^1.3.2:
version "1.19.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c"
integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==
dependencies:
is-core-module "^2.1.0"
path-parse "^1.0.6"

resolve@^1.11.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
dependencies:
is-core-module "^2.2.0"
path-parse "^1.0.6"

rollup-plugin-commonjs@10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz#417af3b54503878e084d127adf4d1caf8beb86fb"
Expand Down

0 comments on commit 27ccba8

Please sign in to comment.