-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.js
More file actions
54 lines (48 loc) · 1.54 KB
/
esbuild.config.js
File metadata and controls
54 lines (48 loc) · 1.54 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
import * as esbuild from 'esbuild';
import { resolve, dirname } from 'path';
import { existsSync } from 'fs';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const aliasPlugin = {
name: 'alias',
setup(build) {
build.onResolve({ filter: /^@/ }, (args) => {
const newPath = args.path.replace('@', 'src');
const dtsPath = resolve(__dirname, newPath + '.d.ts');
const tsPath = resolve(__dirname, newPath + '.ts');
if (existsSync(dtsPath)) return { path: dtsPath, namespace: 'file' };
if (existsSync(tsPath)) return { path: tsPath, namespace: 'file' };
const dirPath = resolve(__dirname, newPath);
const indexTsPath = resolve(dirPath, 'index.ts');
const indexDtsPath = resolve(dirPath, 'index.d.ts');
if (existsSync(indexTsPath)) return { path: indexTsPath, namespace: 'file' };
if (existsSync(indexDtsPath)) return { path: indexDtsPath, namespace: 'file' };
});
},
};
await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
outdir: 'dist',
format: 'esm',
splitting: true,
sourcemap: false,
minify: false,
target: ['es2020'],
external: ['react', 'react-dom', 'zustand'],
plugins: [aliasPlugin],
});
await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
outdir: 'dist',
format: 'cjs',
platform: 'node',
outExtension: { '.js': '.cjs' },
sourcemap: false,
minify: false,
target: ['es2020'],
external: ['react', 'react-dom', 'zustand'],
plugins: [aliasPlugin],
});