Skip to content

Commit fb129eb

Browse files
committed
use esbuild to bundle
1 parent 72c4b87 commit fb129eb

File tree

8 files changed

+1395
-31
lines changed

8 files changed

+1395
-31
lines changed

.vscode/extensions.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
// See http://go.microsoft.com/fwlink/?LinkId=827846
33
// for the documentation about the extensions.json format
4-
"recommendations": ["dbaeumer.vscode-eslint"]
4+
"recommendations": [
5+
"dbaeumer.vscode-eslint",
6+
"connor4312.esbuild-problem-matchers"
7+
]
58
}

.vscode/tasks.json

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,55 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7-
"type": "npm",
8-
"script": "watch",
9-
"problemMatcher": "$tsc-watch",
10-
"isBackground": true,
7+
"label": "watch",
8+
"dependsOn": ["npm: watch:tsc", "npm: watch:esbuild"],
119
"presentation": {
1210
"reveal": "never"
1311
},
1412
"group": {
1513
"kind": "build",
1614
"isDefault": true
1715
}
16+
},
17+
{
18+
"type": "npm",
19+
"script": "watch:esbuild",
20+
"group": "build",
21+
"problemMatcher": "$esbuild-watch",
22+
"isBackground": true,
23+
"label": "npm: watch:esbuild",
24+
"presentation": {
25+
"group": "watch",
26+
"reveal": "never"
27+
}
28+
},
29+
{
30+
"type": "npm",
31+
"script": "watch:tsc",
32+
"group": "build",
33+
"problemMatcher": "$tsc-watch",
34+
"isBackground": true,
35+
"label": "npm: watch:tsc",
36+
"presentation": {
37+
"group": "watch",
38+
"reveal": "never"
39+
}
40+
},
41+
{
42+
"type": "npm",
43+
"script": "watch-tests",
44+
"problemMatcher": "$tsc-watch",
45+
"isBackground": true,
46+
"presentation": {
47+
"reveal": "never",
48+
"group": "watchers"
49+
},
50+
"group": "build"
51+
},
52+
{
53+
"label": "tasks: watch-tests",
54+
"dependsOn": ["npm: watch", "npm: watch-tests"],
55+
"problemMatcher": []
1856
}
1957
]
2058
}

.vscodeignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ vsc-extension-quickstart.md
1313
.history
1414
static/*.dot
1515
pnpm-lock.yaml
16-
eslint.config.mjs
16+
eslint.config.mjs
17+
esbuild.mjs

esbuild.mjs

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

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@
5858
"scripts": {
5959
"deploy": "vsce publish --no-dependencies",
6060
"deploy_ovsx": "ovsx publish --no-dependencies",
61-
"vscode:prepublish": "pnpm run compile",
62-
"compile": "tsc -p ./",
63-
"watch": "tsc -watch -p ./",
61+
"vscode:prepublish": "pnpm run check-types && node esbuild.mjs --production",
62+
"check-types": "tsc --noEmit",
63+
"compile": "pnpm run check-types && node esbuild.mjs",
64+
"watch": "npm-run-all -p watch:*",
65+
"watch:esbuild": "node esbuild.mjs --watch",
66+
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
6467
"pretest": "pnpm run compile && pnpm run lint",
6568
"package": "vsce package --no-dependencies",
6669
"lint": "eslint src",
@@ -77,10 +80,12 @@
7780
"@types/vscode": "1.65.0",
7881
"@vscode/test-electron": "^2.4.1",
7982
"@vscode/vsce": "^3.2.1",
83+
"esbuild": "^0.24.0",
8084
"eslint": "^9.15.0",
8185
"glob": "^11.0.0",
8286
"lint-staged": "^15.2.10",
8387
"mocha": "^10.8.2",
88+
"npm-run-all": "^4.1.5",
8489
"ovsx": "^0.10.1",
8590
"prettier": "^3.3.3",
8691
"simple-git-hooks": "^2.11.1",

0 commit comments

Comments
 (0)