Skip to content

Commit 8a45fa8

Browse files
implemented bundler
1 parent af8201e commit 8a45fa8

File tree

7 files changed

+1337
-30
lines changed

7 files changed

+1337
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.vscode-test
33
node_modules
44
out
5+
dist

.vscodeignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.github/**
2+
.vscode/**
3+
.vscode-test/**
4+
5+
src/**
6+
node_modules/**
7+
8+
.gitignore
9+
**/tsconfig.json
10+
**/.eslintrc.json
11+
**/*.ts

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(` ${location.file}:${location.line}:${location.column}:`);
20+
});
21+
console.log('[watch] build finished');
22+
});
23+
},
24+
};
25+
26+
async function main() {
27+
const ctx = await esbuild.context({
28+
entryPoints: [
29+
'src/extension.ts'
30+
],
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+
});

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,28 @@
1010
},
1111
"categories": ["Other"],
1212
"activationEvents": ["onLanguage:dart"],
13-
"main": "./out/extension.js",
13+
"main": "./dist/extension.js",
1414
"scripts": {
15-
"vscode:prepublish": "npm run compile",
16-
"compile": "tsc -p ./",
17-
"watch": "tsc -watch -p ./",
18-
"package": "vsce package --no-dependencies -o ./vs-code-format-on-save.vsix"
15+
"vscode:prepublish": "pnpm run package",
16+
"compile": "pnpm run check-types && node esbuild.js",
17+
"watch": "npm-run-all -p watch:*",
18+
"watch:esbuild": "node esbuild.js --watch",
19+
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
20+
"package": "pnpm run check-types && node esbuild.js --production",
21+
"compile-tests": "tsc -p . --outDir out",
22+
"watch-tests": "tsc -p . -w --outDir out",
23+
"pretest": "pnpm run compile-tests && pnpm run compile",
24+
"check-types": "tsc --noEmit"
1925
},
2026
"icon": "images/OverReact_Logo.png",
2127
"devDependencies": {
2228
"@types/node": "20.x",
2329
"@types/semver": "^7.5.8",
2430
"@types/vscode": "^1.97.0",
2531
"@vscode/vsce": "^3.2.2",
26-
"typescript": "^5.7.3"
32+
"typescript": "^5.7.3",
33+
"esbuild": "^0.24.2",
34+
"npm-run-all": "^4.1.5"
2735
},
2836
"dependencies": {
2937
"semver": "^7.7.1",

0 commit comments

Comments
 (0)