-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
86 lines (83 loc) · 1.9 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import babel from '@rollup/plugin-babel'
import autoExternal from 'rollup-plugin-auto-external'
import cleanup from 'rollup-plugin-cleanup'
import dts from 'rollup-plugin-dts'
import json from '@rollup/plugin-json'
import commonjs from '@rollup/plugin-commonjs';
const PACKAGE_ROOT_PATH = process.cwd()
const PACKAGE_NAME = PACKAGE_ROOT_PATH.split('/').at(-1)
const extensions = [
'.ts', '.tsx',
];
export default [
{
input: `${PACKAGE_ROOT_PATH}/src/index.ts`,
external: [/@babel\/runtime/],
output: [{
file: 'dist/bundle.cjs.js',
format: 'cjs',
},
{
file: 'dist/bundle.esm.js',
format: 'esm',
},
{
name: PACKAGE_NAME,
file: 'dist/bundle.umd.js',
format: 'umd',
},
],
plugins: [
// Allows node_modules resolution
resolve({ extensions }),
json(),
// Compile TypeScript/JavaScript files
babel({
extensions,
include: ['src/**/*'],
babelHelpers: 'runtime',
presets: [
"@babel/env",
"@babel/typescript"
],
plugins: [
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-export-namespace-from',
['@babel/plugin-transform-runtime', {
'helpers': true,
'regenerator': true
}]
]
}),
autoExternal()
],
},
// types generation
{
input: 'src/index.ts',
output: {
dir: `${PACKAGE_ROOT_PATH}/types`,
format: 'es'
},
plugins: [
commonjs(),
resolve(),
json(),
typescript({ tsconfig: './tsconfig.json' }),
autoExternal(),
]
},
// bundle types files
{
input: './types/index.d.ts',
output: [{
file: 'dist/index.d.ts',
format: 'es'
}],
plugins: [
dts(),
],
}
]