esbuild.js 1.2 KB

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