| 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(`[esbuild] ERROR ${text}`); |
| 19 | if (location) { |
| 20 | console.error(` ${location.file}:${location.line}:${location.column}:`); |
| 21 | } |
| 22 | }); |
| 23 | console.log("[watch] build finished"); |
| 24 | }); |
| 25 | }, |
| 26 | }; |
| 27 | |
| 28 | async function main() { |
| 29 | const ctx = await esbuild.context({ |
| 30 | entryPoints: ["src/extension.ts"], |
| 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: [esbuildProblemMatcherPlugin], |
| 41 | }); |
| 42 | if (watch) { |
| 43 | await ctx.watch(); |
| 44 | } else { |
| 45 | await ctx.rebuild(); |
| 46 | await ctx.dispose(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | main().catch((error) => { |
| 51 | console.error(error); |
| 52 | process.exit(1); |
| 53 | }); |