esbuild.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2015 - present Microsoft Corporation
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. /*
  25. * This supports using esbuild to bundle the extension for releases. This is
  26. * invoked through package.json.
  27. *
  28. * For information about this, see:
  29. * https://code.visualstudio.com/api/working-with-extensions/bundling-extension
  30. */
  31. const esbuild = require('esbuild');
  32. const production = process.argv.includes('--production');
  33. const watch = process.argv.includes('--watch');
  34. /**
  35. * @type {import('esbuild').Plugin}
  36. */
  37. const esbuildProblemMatcherPlugin = {
  38. name: 'esbuild-problem-matcher',
  39. setup(build) {
  40. build.onStart(() => {
  41. console.log('[watch] build started');
  42. });
  43. build.onEnd((result) => {
  44. result.errors.forEach(({ text, location }) => {
  45. console.error(`✘ [ERROR] ${text}`);
  46. console.error(
  47. ` ${location.file}:${location.line}:${location.column}:`
  48. );
  49. });
  50. console.log('[watch] build finished');
  51. });
  52. },
  53. };
  54. async function main() {
  55. const ctx = await esbuild.context({
  56. entryPoints: ['src/extension.ts'],
  57. bundle: true,
  58. format: 'cjs',
  59. minify: production,
  60. sourcemap: !production,
  61. sourcesContent: false,
  62. platform: 'node',
  63. outfile: 'dist/extension.js',
  64. external: ['vscode'],
  65. logLevel: 'silent',
  66. plugins: [
  67. /* add to the end of plugins array */
  68. esbuildProblemMatcherPlugin,
  69. ],
  70. });
  71. if (watch) {
  72. await ctx.watch();
  73. } else {
  74. await ctx.rebuild();
  75. await ctx.dispose();
  76. }
  77. }
  78. main().catch((e) => {
  79. console.error(e);
  80. process.exit(1);
  81. });