-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
rollup.config.js
44 lines (42 loc) · 1.09 KB
/
rollup.config.js
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
import nodeResolvePlugin from '@rollup/plugin-node-resolve'
import esbuildPlugin from 'rollup-plugin-esbuild'
import dtsPlugin from 'rollup-plugin-dts'
function createConfig({ dts, esm } = {}) {
let file = 'dist/index.js'
if (dts) {
file = file.replace('.js', '.d.ts')
}
if (esm) {
file = file.replace('.js', '.mjs')
}
return {
input: 'src/index.ts',
output: {
format: dts || esm ? 'esm' : 'cjs',
file,
exports: 'named',
},
plugins: [
nodeResolvePlugin({
mainFields: dts ? ['types', 'typings'] : ['module', 'main'],
extensions: dts ? ['.d.ts', '.ts'] : ['.js', '.json', '.mjs'],
customResolveOptions: {
moduleDirectories: dts
? ['node_modules/@types', 'node_modules']
: ['node_modules'],
},
}),
!dts && require('@rollup/plugin-commonjs')(),
!dts &&
esbuildPlugin({
target: 'es2017',
}),
dts && dtsPlugin(),
].filter(Boolean),
}
}
export default [
createConfig(),
createConfig({ dts: true }),
createConfig({ esm: true }),
]