forked from gregberge/svgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
49 lines (46 loc) · 1.13 KB
/
rollup.config.mjs
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
import { resolve } from 'node:path'
import { readFileSync } from 'node:fs'
import json from '@rollup/plugin-json'
import dts from 'rollup-plugin-dts'
import esbuild from 'rollup-plugin-esbuild'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = JSON.parse(
readFileSync(resolve(process.cwd(), './package.json'), 'utf-8'),
)
const name = pkg.main ? pkg.main.replace(/\.js$/, '') : './dist/index'
const bundle = (config) => ({
...config,
input: 'src/index.ts',
external: (id) => !/^[./]/.test(id),
})
export default [
bundle({
plugins: [json(), esbuild()],
output: [
{
file: `${name}.js`,
format: 'cjs',
sourcemap: Boolean(pkg.main),
exports: 'auto',
},
],
}),
...(pkg.main
? [
bundle({
plugins: [
dts({
compilerOptions: {
// https://github.com/Swatinem/rollup-plugin-dts/issues/143
preserveSymlinks: false,
},
}),
],
output: {
file: `${name}.d.ts`,
format: 'es',
},
}),
]
: []),
]