|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import esbuild from 'esbuild'; |
| 7 | +import console from 'node:console'; |
| 8 | +import process from 'node:process'; |
| 9 | + |
| 10 | +const production = process.argv[2] === '--production'; |
| 11 | +const watch = process.argv[2] === '--watch'; |
| 12 | +let desktopContext, browserContext; |
| 13 | + |
| 14 | +// This is the base config that will be used by both web and desktop versions of the extension |
| 15 | +const baseConfig = { |
| 16 | + entryPoints: ['./src/extension.ts'], // the entry point of this extension, 📖 -> https://esbuild.github.io/api/#entry-points |
| 17 | + bundle: true, |
| 18 | + external: ['vscode'], // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be packaged, 📖 -> https://esbuild.github.io/api/#external |
| 19 | + sourcemap: !production, |
| 20 | + minify: production, |
| 21 | + format: 'cjs', |
| 22 | + target: 'ES2022', // VS Code 1.82 onwards will support ES2022, this also overrides tsconfig.json. |
| 23 | +}; |
| 24 | + |
| 25 | +// Build both desktop and web versions of the extension in parallel |
| 26 | +// By using .context() instead of .build() we can rebuild in watch mode when the source changes |
| 27 | +try { |
| 28 | + [desktopContext, browserContext] = await Promise.all([ |
| 29 | + // https://esbuild.github.io/getting-started/#bundling-for-node |
| 30 | + esbuild.context({ |
| 31 | + ...baseConfig, |
| 32 | + outfile: './dist/extension.js', |
| 33 | + platform: 'node', |
| 34 | + }), |
| 35 | + // If you're building for the browser, you'll need to generate a second bundle which is suitable |
| 36 | + // https://esbuild.github.io/getting-started/#bundling-for-the-browser |
| 37 | + esbuild.context({ |
| 38 | + ...baseConfig, |
| 39 | + outfile: './dist/browser.js', |
| 40 | + platform: 'browser', |
| 41 | + }), |
| 42 | + ]); |
| 43 | +} catch (e) { |
| 44 | + console.error(e); |
| 45 | + process.exit(1); |
| 46 | +} |
| 47 | + |
| 48 | +if (watch) { |
| 49 | + await desktopContext.watch(); |
| 50 | + await browserContext.watch(); |
| 51 | +} else { |
| 52 | + desktopContext.rebuild(); |
| 53 | + browserContext.rebuild(); |
| 54 | + |
| 55 | + desktopContext.dispose(); |
| 56 | + browserContext.dispose(); |
| 57 | +} |
0 commit comments