-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
49 lines (44 loc) · 1.23 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
45
46
47
48
49
import alias from '@rollup/plugin-alias'
import commonjs from '@rollup/plugin-commonjs'
import nodeResolve from '@rollup/plugin-node-resolve'
import path from 'path'
import swc from 'rollup-plugin-swc3'
import { dependencies } from './package.json'
const root = __dirname
const dependenciesNames = Object.keys(dependencies)
const createConfig = ({ dir, format, input = 'index.ts' }) => {
/** @type {import('rollup').RollupOptions} */
const config = {
external: new RegExp(dependenciesNames.join('|')),
input: `src/${input}`,
output: {
dir,
exports: 'named',
format,
entryFileNames: `[name].${format === 'esm' ? 'mjs' : 'js'}`,
},
plugins: [
alias({
entries: {
'~': path.resolve(root, 'src'),
},
}),
commonjs(),
nodeResolve({
extensions: ['.ts'],
}),
swc({
jsc: {
externalHelpers: true,
},
tsconfig: path.resolve(root, 'tsconfig.code.json'),
}),
],
}
return config
}
export default [
createConfig({ dir: 'lib', format: 'cjs' }),
createConfig({ dir: 'esm', format: 'esm' }),
createConfig({ dir: 'dist', format: 'esm', input: 'cli.ts' }),
]