Skip to content

Commit

Permalink
chore: setup esbuild for bundling typescript (#16)
Browse files Browse the repository at this point in the history
use the bundling extensions documentation as a guide for setting up
esbuild. unfortunately, esbuild is necessary since bun does not support
the "cjs" output format yet, which is required for vscode extensions.

see: https://code.visualstudio.com/api/working-with-extensions/bundling-extension#using-esbuild
  • Loading branch information
lewxdev authored Jul 10, 2024
1 parent 84ad254 commit e91f40f
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:

- run: |
bun install
bun run vsce package
echo "filepath=$(ls *.vsix)" >> $GITHUB_ENV
echo "version=$(ls *.vsix | grep -oE '\d+\.\d+\.\d+')" >> $GITHUB_ENV
bun run build:vsix
echo "filepath=$(ls dist/*.vsix)" >> $GITHUB_ENV
echo "version=$(ls dist/*.vsix | grep -oE '\d+\.\d+\.\d+')" >> $GITHUB_ENV
- env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
Expand Down
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"args": [
"${workspaceFolder}/..",
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}"
]
"--extensionDevelopmentPath=${workspaceFolder}/dist"
],
"preLaunchTask": "build extension"
}
]
}
10 changes: 10 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build extension",
"type": "shell",
"command": "bun run build"
}
]
}
Binary file modified bun.lockb
Binary file not shown.
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"minimal",
"theme"
],
"main": "src/extension.js",
"activationEvents": [
"onStartupFinished"
],
"contributes": {
"iconThemes": [
{
Expand All @@ -45,13 +49,20 @@
]
},
"scripts": {
"build": "bun run clean && bun run scripts/build.ts",
"build:vsix": "bun run build --production",
"clean": "git clean -xdf dist",
"prepare": "husky"
},
"devDependencies": {
"@commitlint/cli": "^19",
"@commitlint/config-conventional": "^19",
"@tsconfig/bun": "^1.0.7",
"@tsconfig/strictest": "^2.0.5",
"@types/bun": "^1.1.6",
"@types/vscode": "^1.87",
"@vscode/vsce": "^2",
"@vscode/vsce": "^2.25.0",
"esbuild": "^0.23.0",
"husky": "^9"
},
"commitlint": {
Expand Down
36 changes: 36 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { build } from "esbuild";

const isProduction = process.argv.includes("--production");

// see: https://code.visualstudio.com/api/working-with-extensions/bundling-extension#using-esbuild
await build({
entryPoints: [
"static/**/*",
"theme/**/*",
"src/extension.ts",
"package.json",
"package.nls.json",
"CHANGELOG.md",
"LICENSE.md",
"README.md",
],
loader: {
".json": "copy",
".md": "copy",
".png": "copy",
".svg": "copy",
},
outdir: "dist",
external: ["vscode"],
format: "cjs",
platform: "node",
bundle: true,
sourcesContent: false,
minify: isProduction,
sourcemap: !isProduction,
});

if (isProduction) {
const { createVSIX } = await import("@vscode/vsce");
await createVSIX({ cwd: "dist" });
}
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as vscode from "vscode";

export function activate(context: vscode.ExtensionContext) {
console.log(`[${context.extension.id}] active`);
}
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["@tsconfig/bun", "@tsconfig/strictest"],
"include": ["scripts", "src"]
}

0 comments on commit e91f40f

Please sign in to comment.