Skip to content

Commit

Permalink
release: bundle files and reduce size of VSIX. (#10)
Browse files Browse the repository at this point in the history
This commit uses esbuild to bundle the extension into a single JavaScript file.

It also ensures only what's needed is put into the package.
  • Loading branch information
peterhuene authored Oct 29, 2024
1 parent 63bda6a commit f769dc6
Show file tree
Hide file tree
Showing 6 changed files with 501 additions and 291 deletions.
2 changes: 1 addition & 1 deletion .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from "@vscode/test-cli";

export default defineConfig({
files: "out/test/**/*.test.js",
files: "dist/test/**/*.test.js",
});
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "extensionHost",
"request": "launch",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
}
]
Expand Down
20 changes: 11 additions & 9 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
.vscode/**
.vscode-test/**
src/**
.github
.vscode
node_modules
src
.eslintrc.json
.gitignore
.vscode-test.mjs
.vscodeignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
**/.vscode-test.*
esbuild.js
tsconfig.json
tsconfig.prod.json
yarn.lock
56 changes: 56 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const esbuild = require("esbuild");

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

async function main() {
const ctx = await esbuild.context({
entryPoints: ["src/extension.ts"],
bundle: true,
format: "cjs",
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: "node",
outfile: "dist/extension.js",
external: ["vscode"],
logLevel: "silent",
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}

/**
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: "esbuild-problem-matcher",

setup(build) {
build.onStart(() => {
console.log("[watch] build started");
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(
` ${location.file}:${location.line}:${location.column}:`,
);
});
console.log("[watch] build finished");
});
},
};

main().catch((e) => {
console.error(e);
process.exit(1);
});
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"Bioinformatics"
],
"preview": true,
"main": "./out/extension.js",
"main": "./dist/extension.js",
"activationEvents": [],
"contributes": {
"languages": [
Expand Down Expand Up @@ -99,12 +99,13 @@
]
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p tsconfig.prod.json",
"watch": "tsc -watch -p tsconfig.json",
"pretest": "tsc -p tsconfig.json && yarn run lint",
"lint": "eslint src --ext ts",
"test": "vscode-test"
"compile": "yarn run check-types && node esbuild.js",
"check-types": "tsc --noEmit",
"watch": "npm-run-all -p watch:*",
"watch:esbuild": "node esbuild.js --watch",
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
"vscode:prepublish": "yarn run package",
"package": "yarn run check-types && node esbuild.js --production"
},
"extensionDependencies": [
"mindaro-dev.file-downloader"
Expand All @@ -125,6 +126,7 @@
"@typescript-eslint/parser": "^7.11.0",
"@vscode/test-cli": "^0.0.9",
"@vscode/test-electron": "^2.4.0",
"esbuild": "^0.24.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"typescript": "^5.4.5"
Expand Down
Loading

0 comments on commit f769dc6

Please sign in to comment.