forked from dagrejs/dagre
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
62 lines (52 loc) · 1.36 KB
/
Copy pathbuild.js
File metadata and controls
62 lines (52 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const esbuild = require('esbuild');
const fs = require('fs');
const { dependencies } = require('./package.json');
// Get all production dependencies to be marked as external (not bundled)
const external = Object.keys(dependencies || {});
const sharedConfig = {
entryPoints: ['index.js'],
bundle: true,
minify: true,
sourcemap: true,
target: 'es2018',
legalComments: 'linked',
external: external.concat([
'@dagrejs/graphlib'
]),
};
async function build() {
// 1. CommonJS (CJS) - For Node.js `require()`
await esbuild.build({
...sharedConfig,
outfile: 'dist/dagre.cjs.js',
format: 'cjs',
platform: 'node',
});
// 2. ES Module (ESM) - For modern bundlers/native ES imports
await esbuild.build({
...sharedConfig,
outfile: 'dist/dagre.esm.js',
format: 'esm',
platform: 'neutral',
});
const iifeConfig = {
...sharedConfig,
format: 'iife',
globalName: 'dagre',
platform: 'browser',
};
// 3. IIFE/UMD - For direct browser script tag
await esbuild.build({
...iifeConfig,
outfile: 'dist/dagre.min.js',
});
// 4. IIFE/UMD - For direct browser script tag, unminified
await esbuild.build({
...iifeConfig,
outfile: 'dist/dagre.js',
minify: false,
});
fs.copyFileSync('index.d.ts', 'dist/dagre.d.ts');
console.log('Build complete! 🚀');
}
build().catch(() => process.exit(1));