-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathesbuild.config.js
More file actions
65 lines (58 loc) Β· 1.65 KB
/
esbuild.config.js
File metadata and controls
65 lines (58 loc) Β· 1.65 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
const esbuild = require('esbuild');
const path = require('path');
const createBuildConfig = (format) => ({
entryPoints: ['src/index.ts'],
bundle: true,
format,
outfile: format === 'esm' ? 'dist/index.esm.js' : 'dist/index.js',
external: ['react', 'react-dom'],
target: ['es2020'],
jsx: 'automatic',
jsxImportSource: 'react',
minify: process.env.NODE_ENV === 'production',
sourcemap: true,
platform: 'browser',
splitting: false,
loader: {
'.tsx': 'tsx',
'.ts': 'ts',
'.js': 'js',
'.jsx': 'jsx'
},
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}
});
const buildAll = async () => {
try {
console.log('π Building ESM bundle...');
await esbuild.build(createBuildConfig('esm'));
console.log('β
ESM bundle built successfully');
console.log('π Building CJS bundle...');
await esbuild.build(createBuildConfig('cjs'));
console.log('β
CJS bundle built successfully');
console.log('π All bundles built successfully!');
} catch (error) {
console.error('β Build failed:', error);
process.exit(1);
}
};
const watch = async () => {
try {
console.log('π Starting watch mode for ESM bundle...');
const ctx = await esbuild.context(createBuildConfig('esm'));
await ctx.watch();
console.log('β
Watch mode active - listening for changes...');
} catch (error) {
console.error('β Watch mode failed:', error);
process.exit(1);
}
};
// Check command line arguments
const args = process.argv.slice(2);
if (args.includes('--watch')) {
watch();
} else {
buildAll();
}
module.exports = { createBuildConfig, buildAll, watch };