esbuild.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. const baseConfig = {
  23. bundle: true,
  24. minify: production,
  25. sourcemap: !production,
  26. logLevel: "silent",
  27. plugins: [
  28. /* add to the end of plugins array */
  29. esbuildProblemMatcherPlugin,
  30. ],
  31. }
  32. const extensionConfig = {
  33. ...baseConfig,
  34. entryPoints: ["src/extension.ts"],
  35. format: "cjs",
  36. sourcesContent: false,
  37. platform: "node",
  38. outfile: "dist/extension.js",
  39. external: ["vscode"],
  40. }
  41. async function main() {
  42. const extensionCtx = await esbuild.context(extensionConfig)
  43. if (watch) {
  44. await extensionCtx.watch()
  45. } else {
  46. await extensionCtx.rebuild()
  47. await extensionCtx.dispose()
  48. }
  49. }
  50. main().catch((e) => {
  51. console.error(e)
  52. process.exit(1)
  53. })