|
1 | | -const esbuild = require('esbuild'); |
2 | | -const fs = require('fs'); |
3 | | -const path = require('path'); |
4 | | - |
5 | | -// Build configurations for different module formats |
6 | | -const builds = [ |
7 | | - // ES Module (for bundlers like webpack, vite, rollup) |
8 | | - { |
9 | | - entryPoints: ['src/index.js'], |
10 | | - bundle: true, |
11 | | - minify: false, |
12 | | - sourcemap: true, |
13 | | - target: ['es2018'], |
14 | | - format: 'esm', |
15 | | - outfile: 'dist/yasgui-graph-plugin.esm.js', |
16 | | - external: [], // Bundle vis-network |
17 | | - loader: { |
18 | | - '.js': 'js', |
19 | | - }, |
20 | | - }, |
21 | | - // CommonJS (for Node.js) |
22 | | - { |
23 | | - entryPoints: ['src/index.js'], |
24 | | - bundle: true, |
25 | | - minify: false, |
26 | | - sourcemap: true, |
27 | | - target: ['es2018'], |
28 | | - format: 'cjs', |
29 | | - outfile: 'dist/yasgui-graph-plugin.cjs.js', |
30 | | - external: [], // Bundle vis-network |
31 | | - loader: { |
32 | | - '.js': 'js', |
33 | | - }, |
34 | | - }, |
35 | | - // IIFE (for browsers via unpkg.com and script tags) |
36 | | - { |
37 | | - entryPoints: ['src/index.js'], |
38 | | - bundle: true, |
39 | | - minify: true, |
40 | | - sourcemap: true, |
41 | | - target: ['es2018'], |
42 | | - format: 'iife', |
43 | | - globalName: 'GraphPlugin', |
44 | | - outfile: 'dist/yasgui-graph-plugin.min.js', |
45 | | - external: [], // Bundle vis-network for browser usage |
46 | | - loader: { |
47 | | - '.js': 'js', |
48 | | - }, |
49 | | - }, |
50 | | -]; |
51 | | - |
52 | | -// TypeScript declaration content |
53 | | -const typeDeclaration = `declare module '@matdata/yasgui-graph-plugin'; |
54 | | -`; |
55 | | - |
56 | | -// Build all formats |
57 | | -Promise.all(builds.map(config => esbuild.build(config))) |
58 | | - .then(() => { |
59 | | - // Create TypeScript declaration file |
60 | | - const distDir = path.join(__dirname, 'dist'); |
61 | | - if (!fs.existsSync(distDir)) { |
62 | | - fs.mkdirSync(distDir, { recursive: true }); |
63 | | - } |
64 | | - fs.writeFileSync(path.join(distDir, 'index.d.ts'), typeDeclaration); |
65 | | - |
66 | | - console.log('✅ Build complete:'); |
67 | | - console.log(' - dist/yasgui-graph-plugin.esm.js (ES Module for bundlers)'); |
68 | | - console.log(' - dist/yasgui-graph-plugin.cjs.js (CommonJS for Node.js)'); |
69 | | - console.log(' - dist/yasgui-graph-plugin.min.js (IIFE for browsers/unpkg)'); |
70 | | - console.log(' - dist/index.d.ts (TypeScript declarations)'); |
71 | | - }) |
72 | | - .catch((err) => { |
73 | | - console.error('❌ Build failed:', err); |
74 | | - process.exit(1); |
75 | | - }); |
| 1 | +const esbuild = require('esbuild'); |
| 2 | +const fs = require('fs'); |
| 3 | +const path = require('path'); |
| 4 | + |
| 5 | +// Build configurations for different module formats |
| 6 | +const buildConfigs = [ |
| 7 | + // ES Module (for bundlers like webpack, vite, rollup) |
| 8 | + { |
| 9 | + entryPoints: ['src/index.js'], |
| 10 | + bundle: true, |
| 11 | + minify: false, |
| 12 | + sourcemap: true, |
| 13 | + target: ['es2018'], |
| 14 | + format: 'esm', |
| 15 | + outfile: 'dist/yasgui-graph-plugin.esm.js', |
| 16 | + external: [], // Bundle vis-network |
| 17 | + loader: { |
| 18 | + '.js': 'js', |
| 19 | + }, |
| 20 | + }, |
| 21 | + // CommonJS (for Node.js) |
| 22 | + { |
| 23 | + entryPoints: ['src/index.js'], |
| 24 | + bundle: true, |
| 25 | + minify: false, |
| 26 | + sourcemap: true, |
| 27 | + target: ['es2018'], |
| 28 | + format: 'cjs', |
| 29 | + outfile: 'dist/yasgui-graph-plugin.cjs.js', |
| 30 | + external: [], // Bundle vis-network |
| 31 | + loader: { |
| 32 | + '.js': 'js', |
| 33 | + }, |
| 34 | + }, |
| 35 | + // IIFE (for browsers via unpkg.com and script tags) |
| 36 | + { |
| 37 | + entryPoints: ['src/index.js'], |
| 38 | + bundle: true, |
| 39 | + minify: true, |
| 40 | + sourcemap: true, |
| 41 | + target: ['es2018'], |
| 42 | + format: 'iife', |
| 43 | + globalName: 'GraphPlugin', |
| 44 | + outfile: 'dist/yasgui-graph-plugin.min.js', |
| 45 | + external: [], // Bundle vis-network for browser usage |
| 46 | + loader: { |
| 47 | + '.js': 'js', |
| 48 | + }, |
| 49 | + }, |
| 50 | +]; |
| 51 | + |
| 52 | +// TypeScript declaration content |
| 53 | +const typeDeclaration = `declare module '@matdata/yasgui-graph-plugin'; |
| 54 | +`; |
| 55 | + |
| 56 | +// Build all formats |
| 57 | +Promise.all(buildConfigs.map(config => esbuild.build(config))) |
| 58 | + .then(() => { |
| 59 | + // Create TypeScript declaration file |
| 60 | + const distDir = path.join(__dirname, 'dist'); |
| 61 | + if (!fs.existsSync(distDir)) { |
| 62 | + fs.mkdirSync(distDir, { recursive: true }); |
| 63 | + } |
| 64 | + fs.writeFileSync(path.join(distDir, 'index.d.ts'), typeDeclaration); |
| 65 | + |
| 66 | + console.log('✅ Build complete:'); |
| 67 | + console.log(' - dist/yasgui-graph-plugin.esm.js (ES Module for bundlers)'); |
| 68 | + console.log(' - dist/yasgui-graph-plugin.cjs.js (CommonJS for Node.js)'); |
| 69 | + console.log(' - dist/yasgui-graph-plugin.min.js (IIFE for browsers/unpkg)'); |
| 70 | + console.log(' - dist/index.d.ts (TypeScript declarations)'); |
| 71 | + }) |
| 72 | + .catch((err) => { |
| 73 | + console.error('❌ Build failed:', err); |
| 74 | + process.exit(1); |
| 75 | + }); |
0 commit comments