-
Notifications
You must be signed in to change notification settings - Fork 1
/
esbuild.config.ts
46 lines (37 loc) · 1.15 KB
/
esbuild.config.ts
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
import fs from 'node:fs/promises';
import { build, BuildOptions } from 'esbuild';
import { dTSPathAliasPlugin } from './src';
import { devDependencies, peerDependencies } from './package.json';
const DIST_DIR = 'dist';
const EXTERNAL_PACKAGES = Object.keys({ ...devDependencies, ...peerDependencies });
const baseOptions: BuildOptions = {
target: 'es2020',
external: EXTERNAL_PACKAGES,
platform: 'node',
entryPoints: ['./src/index.ts'],
bundle: true,
treeShaking: true,
sourcemap: false,
minify: false,
};
await fs.rm(DIST_DIR, { force: true, recursive: true });
const esmBuild = build({
...baseOptions,
splitting: true,
format: 'esm',
outdir: `${DIST_DIR}/esm`,
banner: {
// fix Error: Dynamic require of `x`(any cjs module) is not supported
js: [
"import { createRequire as topLevelCreateRequire } from 'module';",
'const require = topLevelCreateRequire(import.meta.url);',
].join('\n'),
},
plugins: [dTSPathAliasPlugin({ outputPath: `${DIST_DIR}/typings`, debug: true })],
});
const cjsBuild = build({
...baseOptions,
format: 'cjs',
outdir: `${DIST_DIR}/cjs`,
});
await Promise.all([esmBuild, cjsBuild]);