-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeRollupConfig.js
More file actions
34 lines (31 loc) · 1.01 KB
/
makeRollupConfig.js
File metadata and controls
34 lines (31 loc) · 1.01 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
import { readFileSync } from 'node:fs';
import { defineConfig } from 'rollup';
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';
export const makeRollupConfig = (ext) => {
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
const externals = new Set(
[pkg.dependencies, pkg.peerDependencies, pkg.peerDependenciesMeta]
.filter(Boolean)
.flatMap(Object.keys)
);
return defineConfig([
{
input: `./src/index.${ext}`,
output: [
{ format: 'esm', file: './dist/index.mjs' },
{ format: 'cjs', file: './dist/index.cjs' },
],
plugins: [typescript({ tsconfig: './tsconfig.build.json' })],
external: (source) => externals.has(source.replace(/\/.*/, '')),
},
{
input: `./src/index.${ext}`,
output: [
{ format: 'esm', file: './dist/index.d.mts' },
{ format: 'cjs', file: './dist/index.d.cts' },
],
plugins: [dts({ tsconfig: './tsconfig.build.json' })],
},
]);
};