-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
141 lines (123 loc) · 3.2 KB
/
esbuild.config.mjs
File metadata and controls
141 lines (123 loc) · 3.2 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import * as esbuild from 'esbuild'
import AnalyzerPlugin from 'esbuild-analyzer'
import fs from 'fs'
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
// Externe Dependencies (nicht bündeln)
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.optionalDependencies || {}),
'util'
]
// Gemeinsame Build-Optionen für Node.js (Main Bundle)
const commonNodeOptions = {
bundle: true,
target: 'es2015',
sourcemap: true,
minify: true,
treeShaking: true,
legalComments: 'none',
logLevel: 'info',
external,
minifyWhitespace: true,
minifySyntax: true,
metafile: true,
}
// Gemeinsame Build-Optionen für Browser (Proxy Bundle)
const browserOptions = {
bundle: true,
platform: 'browser',
target: 'es2020',
format: 'esm',
sourcemap: true,
minify: true,
treeShaking: true,
legalComments: 'none',
logLevel: 'info',
external,
minifyWhitespace: true,
minifySyntax: true,
metafile: true,
charset: 'utf8',
}
// Stats-Verzeichnis erstellen
if (!fs.existsSync('stats')) {
fs.mkdirSync('stats', { recursive: true })
}
// Main Bundle (fsxa-api)
console.log('Building main bundle (fsxa-api)...')
// CJS build - use platform: 'node' for proper CommonJS exports
await esbuild.build({
...commonNodeOptions,
platform: 'node',
entryPoints: ['src/index.ts'],
outfile: 'dist/fsxa-api.cjs.js',
format: 'cjs',
plugins: [
AnalyzerPlugin({
outfile: 'stats/fsxa-api-cjs.html',
})
],
})
// ESM build - use platform: 'neutral' to avoid Node.js-specific code
await esbuild.build({
...commonNodeOptions,
platform: 'neutral',
entryPoints: ['src/index.ts'],
outfile: 'dist/fsxa-api.es5.js',
format: 'esm',
plugins: [
AnalyzerPlugin({
outfile: 'stats/fsxa-api-esm.html',
})
],
})
console.log('Main bundle built successfully!')
// Proxy Bundle (fsxa-proxy-api)
console.log('Building proxy bundle (fsxa-proxy-api)...')
await esbuild.build({
...browserOptions,
entryPoints: ['src/proxy.ts'],
outfile: 'proxy/dist/fsxa-proxy-api.cjs.js',
format: 'cjs',
plugins: [
AnalyzerPlugin({
outfile: 'stats/fsxa-proxy-api-cjs.html',
})
],
})
await esbuild.build({
...browserOptions,
entryPoints: ['src/proxy.ts'],
outfile: 'proxy/dist/fsxa-proxy-api.es5.js',
format: 'esm',
plugins: [
AnalyzerPlugin({
outfile: 'stats/fsxa-proxy-api-esm.html',
})
],
})
console.log('Proxy bundle built successfully!')
// Bundle-Größen ausgeben
console.log('\n📦 Bundle Sizes:')
console.log('─'.repeat(60))
const files = [
'dist/fsxa-api.cjs.js',
'dist/fsxa-api.es5.js',
'proxy/dist/fsxa-proxy-api.cjs.js',
'proxy/dist/fsxa-proxy-api.es5.js',
]
files.forEach((file) => {
if (fs.existsSync(file)) {
const stats = fs.statSync(file)
const sizeKB = (stats.size / 1024).toFixed(2)
console.log(`${file.padEnd(45)} ${sizeKB.padStart(10)} KB`)
}
})
console.log('─'.repeat(60))
console.log('\n✓ Bundle analysis reports generated:')
console.log(' - stats/fsxa-api-cjs.html')
console.log(' - stats/fsxa-api-esm.html')
console.log(' - stats/fsxa-proxy-api-cjs.html')
console.log(' - stats/fsxa-proxy-api-esm.html')
console.log('\nBuild complete!')