|
1 | 1 | const esbuild = require('esbuild'); |
2 | 2 |
|
3 | | -// Build configuration |
4 | | -const config = { |
5 | | - entryPoints: ['src/index.js'], |
6 | | - bundle: true, |
7 | | - minify: true, |
8 | | - sourcemap: true, |
9 | | - target: ['es2018'], |
10 | | - format: 'iife', |
11 | | - globalName: 'GraphPlugin', |
12 | | - outfile: 'dist/yasgui-graph-plugin.min.js', |
13 | | - external: [], |
14 | | - // Resolve ES module extensions |
15 | | - loader: { |
16 | | - '.js': 'js', |
| 3 | +// Build configurations for different module formats |
| 4 | +const builds = [ |
| 5 | + // ES Module (for bundlers like webpack, vite, rollup) |
| 6 | + { |
| 7 | + entryPoints: ['src/index.js'], |
| 8 | + bundle: true, |
| 9 | + minify: false, |
| 10 | + sourcemap: true, |
| 11 | + target: ['es2018'], |
| 12 | + format: 'esm', |
| 13 | + outfile: 'dist/yasgui-graph-plugin.esm.js', |
| 14 | + external: ['vis-network'], // Don't bundle vis-network for ESM |
| 15 | + loader: { |
| 16 | + '.js': 'js', |
| 17 | + }, |
17 | 18 | }, |
18 | | -}; |
| 19 | + // CommonJS (for Node.js) |
| 20 | + { |
| 21 | + entryPoints: ['src/index.js'], |
| 22 | + bundle: true, |
| 23 | + minify: false, |
| 24 | + sourcemap: true, |
| 25 | + target: ['es2018'], |
| 26 | + format: 'cjs', |
| 27 | + outfile: 'dist/yasgui-graph-plugin.cjs.js', |
| 28 | + external: ['vis-network'], // Don't bundle vis-network for CJS |
| 29 | + loader: { |
| 30 | + '.js': 'js', |
| 31 | + }, |
| 32 | + }, |
| 33 | + // IIFE (for browsers via unpkg.com and script tags) |
| 34 | + { |
| 35 | + entryPoints: ['src/index.js'], |
| 36 | + bundle: true, |
| 37 | + minify: true, |
| 38 | + sourcemap: true, |
| 39 | + target: ['es2018'], |
| 40 | + format: 'iife', |
| 41 | + globalName: 'GraphPlugin', |
| 42 | + outfile: 'dist/yasgui-graph-plugin.min.js', |
| 43 | + external: [], // Bundle vis-network for browser usage |
| 44 | + loader: { |
| 45 | + '.js': 'js', |
| 46 | + }, |
| 47 | + }, |
| 48 | +]; |
19 | 49 |
|
20 | | -esbuild |
21 | | - .build(config) |
22 | | - .then(() => console.log('✅ Build complete: dist/yasgui-graph-plugin.min.js')) |
| 50 | +// Build all formats |
| 51 | +Promise.all(builds.map(config => esbuild.build(config))) |
| 52 | + .then(() => { |
| 53 | + console.log('✅ Build complete:'); |
| 54 | + console.log(' - dist/yasgui-graph-plugin.esm.js (ES Module for bundlers)'); |
| 55 | + console.log(' - dist/yasgui-graph-plugin.cjs.js (CommonJS for Node.js)'); |
| 56 | + console.log(' - dist/yasgui-graph-plugin.min.js (IIFE for browsers/unpkg)'); |
| 57 | + }) |
23 | 58 | .catch((err) => { |
24 | 59 | console.error('❌ Build failed:', err); |
25 | 60 | process.exit(1); |
|
0 commit comments