-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathbuild.ts
More file actions
58 lines (49 loc) · 1.5 KB
/
build.ts
File metadata and controls
58 lines (49 loc) · 1.5 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
import {build as esbuild, BuildOptions} from 'esbuild';
import {readFileSync} from 'fs';
// Get all production dependencies to be marked as external (not bundled)
const packageJson = JSON.parse(readFileSync('./package.json', 'utf-8'));
const external = Object.keys(packageJson.dependencies || {});
const sharedConfig: BuildOptions = {
entryPoints: ['index.ts'],
bundle: true,
minify: true,
sourcemap: true,
target: 'es2018',
legalComments: 'linked',
external: external.concat([]),
};
async function build(): Promise<void> {
// 1. CommonJS (CJS) - For Node.js `require()`
await esbuild({
...sharedConfig,
outfile: 'dist/graphlib.cjs.js',
format: 'cjs',
platform: 'node',
});
// 2. ES Module (ESM) - For modern bundlers/native ES imports
await esbuild({
...sharedConfig,
outfile: 'dist/graphlib.esm.js',
format: 'esm',
platform: 'neutral',
});
const iifeConfig: BuildOptions = {
...sharedConfig,
format: 'iife',
globalName: 'graphlib',
platform: 'browser',
};
// 3. IIFE/UMD - For direct browser script tag (minified)
await esbuild({
...iifeConfig,
outfile: 'dist/graphlib.min.js',
});
// 4. IIFE/UMD - For direct browser script tag (unminified)
await esbuild({
...iifeConfig,
outfile: 'dist/graphlib.js',
minify: false,
});
console.log('Build complete! 🚀');
}
build().catch(() => process.exit(1));