Skip to content

Commit 472cfbb

Browse files
committed
1 parent c2d7d85 commit 472cfbb

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

esbuild.js

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

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424
"main": "./dist/extension",
2525
"scripts": {
2626
"compile": "webpack --mode development",
27+
"check-types": "tsc --noEmit",
2728
"format": "prettier --config .prettierrc 'src/**/*.ts' --write",
2829
"lint": "eslint src --ext ts",
2930
"package": "webpack --mode production --devtool hidden-source-map",
3031
"publish": "vsce publish",
3132
"pretest": "npm run compile && npm run lint",
3233
"test": "vscode-tmgrammar-test -g tests/support/diff.tmLanguage.json tests/unit/*.test && node ./out/test/runTest.js",
3334
"vscode:prepublish": "npm run package",
34-
"watch": "webpack --mode development --watch"
35+
"watch": "webpack --mode development --watch",
36+
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
37+
"watch:esbuild": "node esbuild.js --watch"
3538
},
3639
"scriptsComment": {
3740
"package": [
@@ -82,4 +85,4 @@
8285
"engines": {
8386
"vscode": "^1.103.0"
8487
}
85-
}
88+
}

0 commit comments

Comments
 (0)