Skip to content

Commit c07fced

Browse files
committed
build: add dual desktop/web build targets
1 parent 73f322f commit c07fced

4 files changed

Lines changed: 30 additions & 11 deletions

File tree

esbuild.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,41 @@ const esbuildProblemMatcherPlugin = {
2222
},
2323
};
2424

25+
/** @type {import('esbuild').BuildOptions} */
26+
const sharedOptions = {
27+
bundle: true,
28+
minify: production,
29+
sourcemap: !production,
30+
sourcesContent: false,
31+
external: ['vscode'],
32+
logLevel: 'silent',
33+
plugins: [esbuildProblemMatcherPlugin],
34+
};
35+
2536
async function main() {
26-
const ctx = await esbuild.context({
37+
// Desktop (Node) build
38+
const nodeCtx = await esbuild.context({
39+
...sharedOptions,
2740
entryPoints: ['src/extension.ts'],
28-
bundle: true,
2941
format: 'cjs',
30-
minify: production,
31-
sourcemap: !production,
32-
sourcesContent: false,
3342
platform: 'node',
3443
outfile: 'dist/extension.js',
35-
external: ['vscode'],
36-
logLevel: 'silent',
37-
plugins: [esbuildProblemMatcherPlugin],
3844
});
45+
46+
// Web (browser) build
47+
const webCtx = await esbuild.context({
48+
...sharedOptions,
49+
entryPoints: ['src/extension.web.ts'],
50+
format: 'cjs',
51+
platform: 'browser',
52+
outfile: 'dist/web/extension.js',
53+
});
54+
3955
if (watch) {
40-
await ctx.watch();
56+
await Promise.all([nodeCtx.watch(), webCtx.watch()]);
4157
} else {
42-
await ctx.rebuild();
43-
await ctx.dispose();
58+
await Promise.all([nodeCtx.rebuild(), webCtx.rebuild()]);
59+
await Promise.all([nodeCtx.dispose(), webCtx.dispose()]);
4460
}
4561
}
4662

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const config: Config = {
1818
'src/**/*.ts',
1919
'!src/types/**',
2020
'!src/extension.ts',
21+
'!src/extension.web.ts',
2122
'!src/__mocks__/**',
2223
'!src/__tests__/**',
2324
],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"vscode.git"
5858
],
5959
"main": "./dist/extension.js",
60+
"browser": "./dist/web/extension.js",
6061
"contributes": {
6162
"commands": [
6263
{

src/providers/lmApiProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// <reference lib="webworker" />
12
import * as vscode from 'vscode';
23
import type { CommitMessageProvider } from './types';
34

0 commit comments

Comments
 (0)