esbuild.js 736 B

123456789101112131415161718192021222324252627282930313233
  1. const esbuild = require('esbuild');
  2. const production = process.argv.includes('--minify');
  3. const watch = process.argv.includes('--watch');
  4. /** @type {esbuild.BuildOptions} */
  5. const config = {
  6. entryPoints: ['src/extension.ts'],
  7. bundle: true,
  8. outfile: 'dist/extension.js',
  9. external: ['vscode'],
  10. format: 'cjs',
  11. platform: 'node',
  12. sourcemap: !production,
  13. minify: production,
  14. treeShaking: true,
  15. };
  16. async function main() {
  17. if (watch) {
  18. const ctx = await esbuild.context(config);
  19. await ctx.watch();
  20. console.log('[esbuild] watching for changes...');
  21. } else {
  22. await esbuild.build(config);
  23. console.log('[esbuild] build complete');
  24. }
  25. }
  26. main().catch((e) => {
  27. console.error(e);
  28. process.exit(1);
  29. });