-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-bundle.mjs
More file actions
67 lines (60 loc) · 1.75 KB
/
build-bundle.mjs
File metadata and controls
67 lines (60 loc) · 1.75 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
63
64
65
66
67
/**
* Bundle SDK into a single JS file
* 将 SDK 打包成单个 JS 文件
*/
import esbuild from 'esbuild';
async function build() {
try {
console.log('📦 Building SDK bundle...');
// Build for browser (IIFE format - can be used directly in HTML)
await esbuild.build({
entryPoints: ['index.ts'],
bundle: true,
format: 'iife',
globalName: 'MindStageSDK',
outfile: 'dist/mindstage-sdk.js',
platform: 'browser',
target: ['es2020'],
minify: false, // Set to true for production
sourcemap: true,
external: ['katex'], // katex is optional peer dependency
banner: {
js: `/*!
* mindstage-sdk
* Mind Map Rendering SDK
* Version: 1.0.0
* License: MIT
*/`,
},
});
console.log('✅ Bundle created: dist/mindstage-sdk.js');
// Also create minified version
await esbuild.build({
entryPoints: ['index.ts'],
bundle: true,
format: 'iife',
globalName: 'MindStageSDK',
outfile: 'dist/mindstage-sdk.min.js',
platform: 'browser',
target: ['es2020'],
minify: true,
sourcemap: false,
external: ['katex'],
banner: {
js: `/*! mindstage-sdk v1.0.0 | MIT License */`,
},
});
console.log('✅ Minified bundle created: dist/mindstage-sdk.min.js');
console.log('');
console.log('📝 Usage in HTML:');
console.log(' <script src="dist/mindstage-sdk.js"></script>');
console.log(' <script>');
console.log(' const { renderMindMapFromJSON } = MindStageSDK;');
console.log(' // renderMindMapFromJSON("#map", data, { collapsible: true })');
console.log(' </script>');
} catch (error) {
console.error('❌ Build failed:', error);
process.exit(1);
}
}
build();