Skip to content

Commit 96a5711

Browse files
committed
Use esbuild for bundling the JavaScript code, instead of webpack
1 parent da8c7b0 commit 96a5711

File tree

4 files changed

+630
-1481
lines changed

4 files changed

+630
-1481
lines changed

esbuild.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const esbuild = require("esbuild");
2+
3+
const production = process.argv.includes("--production");
4+
const watch = process.argv.includes("--watch");
5+
6+
/**
7+
* @type {import('esbuild').Plugin}
8+
*/
9+
const esbuildProblemMatcherPlugin = {
10+
name: "esbuild-problem-matcher",
11+
12+
setup(build) {
13+
build.onStart(() => {
14+
console.log("[watch] build started");
15+
});
16+
build.onEnd((result) => {
17+
result.errors.forEach(({ text, location }) => {
18+
console.error(`✘ [ERROR] ${text}`);
19+
console.error(
20+
` ${location.file}:${location.line}:${location.column}:`,
21+
);
22+
});
23+
console.log("[watch] build finished");
24+
});
25+
},
26+
};
27+
28+
async function main() {
29+
const ctx = await esbuild.context({
30+
entryPoints: ["src/extension.ts"],
31+
bundle: true,
32+
format: "cjs",
33+
minify: production,
34+
sourcemap: !production,
35+
sourcesContent: false,
36+
platform: "node",
37+
outfile: "dist/extension.js",
38+
external: ["vscode"],
39+
logLevel: "silent",
40+
plugins: [
41+
/* add to the end of plugins array */
42+
esbuildProblemMatcherPlugin,
43+
],
44+
});
45+
if (watch) {
46+
await ctx.watch();
47+
} else {
48+
await ctx.rebuild();
49+
await ctx.dispose();
50+
}
51+
}
52+
53+
main().catch((e) => {
54+
console.error(e);
55+
process.exit(1);
56+
});

0 commit comments

Comments
 (0)