Skip to content

Commit 868509c

Browse files
datho7561rgrunber
authored andcommitted
Switch from webpack to esbuild for bundling webviews
This PR uses esbuild instead of webpack to bundle the webviews. This dramatically reduces the time it takes to bundle the webviews, from >50 seconds to <1 second. This PR also modifies the npm scripts and VS Code launch configurations to always recompile the webviews before launching. I also set up eslint to be run before launching the extension. If the extension seems slower to launch in debug mode, this is why. Closes #2875 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 00f8659 commit 868509c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1092
-3681
lines changed

.vscode/launch.json

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"outFiles": [
1717
"${workspaceFolder}/out/src/**/*.js"
1818
],
19-
"preLaunchTask": "npm: watch",
19+
"preLaunchTask": "compile",
2020
"env": {
2121
"VSCODE_REDHAT_TELEMETRY_DEBUG":"true"
2222
}
@@ -31,9 +31,10 @@
3131
"--extensionTestsPath=${workspaceFolder}/out/test/unit"
3232
],
3333
"outFiles": [
34-
"${workspaceFolder}/out/test/unit/**/*.js"
34+
"${workspaceFolder}/out/**/*.js"
3535
],
36-
"preLaunchTask": "npm: watch",
36+
"sourceMaps": true,
37+
"preLaunchTask": "compile",
3738
"env": {
3839
"OST_DISABLE_COVERAGE": "yes",
3940
"VSCODE_REDHAT_TELEMETRY_DEBUG":"true"
@@ -68,8 +69,9 @@
6869
"--extensionTestsPath=${workspaceFolder}/out/test/integration"
6970
],
7071
"outFiles": [
71-
"${workspaceFolder}/out/test/integration/**/*.js"
72+
"${workspaceFolder}/out/**/*.js"
7273
],
74+
"sourceMaps": true,
7375
"preLaunchTask": "instrument",
7476
"env": {
7577
"VSCODE_REDHAT_TELEMETRY_DEBUG":"true"
@@ -89,7 +91,11 @@
8991
"--mocha_config",
9092
"${workspaceFolder}/test/ui/.mocharc.js"
9193
],
92-
"preLaunchTask": "npm: watch",
94+
"outFiles": [
95+
"${workspaceFolder}/out/**/*.js"
96+
],
97+
"sourceMaps": true,
98+
"preLaunchTask": "compile",
9399
"console": "integratedTerminal",
94100
"internalConsoleOptions": "neverOpen",
95101
"env": {
@@ -110,7 +116,11 @@
110116
"--mocha_config",
111117
"${workspaceFolder}/test/ui/.mocharc.js"
112118
],
113-
"preLaunchTask": "npm: watch",
119+
"outFiles": [
120+
"${workspaceFolder}/out/**/*.js"
121+
],
122+
"sourceMaps": true,
123+
"preLaunchTask": "compile",
114124
"console": "integratedTerminal",
115125
"internalConsoleOptions": "neverOpen"
116126
},
@@ -123,12 +133,12 @@
123133
"trace": true
124134
},
125135
{
126-
"type": "pwa-chrome",
127-
"request": "launch",
128-
"name": "Launch 'Devfile Registry viewer' in Chrome",
129-
"file": "${workspaceFolder}/out/devFileRegistryViewer/index.html",
130-
"webRoot": "${workspaceFolder}",
131-
"trace": true
136+
"type": "pwa-chrome",
137+
"request": "launch",
138+
"name": "Launch 'Devfile Registry viewer' in Chrome",
139+
"file": "${workspaceFolder}/out/devFileRegistryViewer/index.html",
140+
"webRoot": "${workspaceFolder}",
141+
"trace": true
132142
}
133143
]
134144
}

.vscode/tasks.json

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,13 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7+
"label": "compile",
78
"type": "npm",
8-
"script": "watch",
9-
"problemMatcher": "$tsc-watch",
10-
"isBackground": true,
9+
"script": "compile",
10+
"problemMatcher": "$tsc",
1111
"presentation": {
12-
"reveal": "never"
12+
"reveal": "silent",
1313
},
14-
"group": {
15-
"kind": "build",
16-
"isDefault": true
17-
}
18-
},
19-
{
20-
"label": "compile",
21-
"type": "typescript",
22-
"problemMatcher": "$tsc",
23-
"group": "build",
24-
"tsconfig": "tsconfig.json"
2514
},
2615
{
2716
"label": "instrument",

CONTRIBUTING.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,10 @@ There are only a few guidelines that we need contributors to follow.
2929
$ npm run build
3030
```
3131

32-
* This downloads the `oc` and `odo` binaries and compiles webviews.
32+
* This downloads the `oc` and `odo` binaries and compiles the code.
3333
2. The extension can now be launched with the `Extension` launch option in the Run and Debug tab (`Ctrl+Shift+D`) in VS Code.
3434
* Note: breakpoints in webview code will not work
3535
3. After making any changes, consider the following before relaunching the extension to ensure the changes are recompiled:
36-
* Changes made to webviews in `src/webview/$WEBVIEW_NAME/app` can be compiled with the corresponding command:
37-
38-
```bash
39-
$ npm run dev:compile:$WEBVIEW_NAME
40-
```
41-
42-
* The list of commands to build the webviews can be found in `package.json` or by running `npm run`
4336
* Changes in version of one of the required tools in `src/tools.json`, run:
4437

4538
```bash

build/esbuild.mjs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*-----------------------------------------------------------------------------------------------
2+
* Copyright (c) Red Hat, Inc. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4+
*-----------------------------------------------------------------------------------------------*/
5+
6+
import * as esbuild from 'esbuild';
7+
import { sassPlugin } from 'esbuild-sass-plugin';
8+
import * as fs from 'fs/promises';
9+
10+
const webviews = [
11+
'cluster',
12+
'create-service',
13+
'describe',
14+
'devfile-registry',
15+
'git-import',
16+
'helm-chart',
17+
'log',
18+
'welcome',
19+
];
20+
21+
function kebabToCamel(text) {
22+
return text.replace(/-./g, searchResult => searchResult.substring(1).toUpperCase());
23+
}
24+
25+
await Promise.all([
26+
...webviews.map(webview =>
27+
esbuild.build({
28+
entryPoints: [
29+
`./src/webview/${webview}/app/index.tsx`,
30+
],
31+
bundle: true,
32+
outfile: `./out/${kebabToCamel(webview)}Viewer/index.js`,
33+
platform: 'browser',
34+
target: 'chrome108',
35+
sourcemap: true,
36+
loader: {
37+
'.png': 'file',
38+
'.svg': 'file',
39+
},
40+
plugins: [
41+
sassPlugin(),
42+
]
43+
})
44+
),
45+
...webviews.map(webview =>
46+
fs.cp(`./src/webview/${webview}/app/index.html`, `./out/${kebabToCamel(webview)}Viewer/index.html`)
47+
),
48+
]);

0 commit comments

Comments
 (0)