|
1 | 1 | const esbuild = require('esbuild'); |
| 2 | +const fs = require('fs'); |
| 3 | +const path = require('path'); |
2 | 4 |
|
3 | | -esbuild.build({ |
4 | | - entryPoints: ['src/extension.ts'], // Your entry file |
5 | | - bundle: true, |
6 | | - outfile: 'out/extension.js', |
7 | | - external: ['vscode'], // Mark vscode as external |
8 | | - platform: 'node', // This ensures the output is suitable for Node.js |
9 | | - target: 'node14', // Set your desired Node.js version |
10 | | - sourcemap: false, |
11 | | - minify: true, // Optionally minify the output |
12 | | -}).catch(() => process.exit(1)); |
| 5 | +// Define the output folder |
| 6 | +const outputFolder = path.resolve(__dirname, 'out'); |
| 7 | + |
| 8 | +// Function to clean the output folder if it exists |
| 9 | +async function cleanOutputFolder() { |
| 10 | + if (fs.existsSync(outputFolder)) { |
| 11 | + await fs.promises.rm(outputFolder, { recursive: true, force: true }); |
| 12 | + console.log('Output folder cleaned.'); |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +// Run the cleaning function and then the esbuild process |
| 17 | +cleanOutputFolder().then(() => { |
| 18 | + esbuild.build({ |
| 19 | + entryPoints: ['src/extension.ts'], // Your entry file |
| 20 | + bundle: true, |
| 21 | + outfile: 'out/extension.js', |
| 22 | + external: ['vscode'], // Mark vscode as external |
| 23 | + platform: 'node', // Ensures the output is suitable for Node.js |
| 24 | + target: 'node14', // Set your desired Node.js version |
| 25 | + sourcemap: false, |
| 26 | + minify: true, // Optionally minify the output |
| 27 | + }).then(() => { |
| 28 | + console.log('Build completed successfully.'); |
| 29 | + }).catch(() => { |
| 30 | + console.error('Build failed.'); |
| 31 | + process.exit(1); |
| 32 | + }); |
| 33 | +}).catch((err) => { |
| 34 | + console.error('Error cleaning output folder:', err); |
| 35 | + process.exit(1); |
| 36 | +}); |
0 commit comments