esbuild.js 1.1 KB

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