-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrollup.config.ts
64 lines (60 loc) · 1.45 KB
/
rollup.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import resolve from '@rollup/plugin-node-resolve';
import { createRequire } from 'node:module';
import path from 'path';
import dts from 'rollup-plugin-dts';
import commonjs from '@rollup/plugin-commonjs';
import esbuild from 'rollup-plugin-esbuild';
import { nodeExternals } from 'rollup-plugin-node-externals';
if (!process.env.PROJECT_CWD) {
throw new Error('PROJECT_CWD is not defined');
}
const rq = createRequire(import.meta.url);
const pkg = rq('./package.json');
const legacyOutputDefaults = {
esModule: true,
interop: 'compat',
};
export default [
{
input: 'src/index.ts',
plugins: [
nodeExternals({ deps: true, peerDeps: true, packagePath: './package.json' }),
commonjs(),
resolve(),
esbuild({
target: 'es2018',
tsconfig: 'tsconfig.build.json',
}),
],
output: [
{
format: 'cjs',
sourcemap: true,
file: pkg.main,
...legacyOutputDefaults,
},
{
format: 'esm',
sourcemap: true,
dir: path.dirname(pkg.module),
preserveModules: true,
preserveModulesRoot: path.join(process.env.PROJECT_CWD, 'src'),
...legacyOutputDefaults,
},
],
},
{
input: './compiled/index.d.ts',
plugins: [dts()],
output: [
{
file: pkg.exports['.'].require.types,
format: 'cjs',
},
{
file: pkg.exports['.'].import.types,
format: 'esm',
},
],
},
];