-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
113 lines (108 loc) · 2.54 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import path from 'node:path';
import fs from 'node:fs';
import terser from '@rollup/plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import { dts } from 'rollup-plugin-dts';
import swc from '@rollup/plugin-swc';
const input = './src/index.ts';
const output = './dist';
const name = 'buddy';
const formats = ['umd', 'cjs', 'esm'];
const defaultExternals = [];
const defaultGlobals = {};
const defaultPlugins = [
commonjs(),
];
export default [
...formats.map(f => ({
input,
plugins: [
resolve({
extensions: ['.js', '.ts', '.json', '.node'],
}),
swc({
swc: {
jsc: {
target: null,
},
env: {
targets: '>=0.2% and not dead',
},
},
}),
...defaultPlugins,
terser(),
],
external: defaultExternals,
output: {
...(f === 'esm'
? { dir: `${output}/esm`, chunkFileNames: '[name].js' }
: { file: `${output}/${name}.${f}.js` }
),
format: f,
name,
sourcemap: true,
globals: defaultGlobals,
...(f === 'esm'
? {
manualChunks: id => {
return id.includes('node_modules')
? 'vendor'
: path.parse(id).name;
},
}
: {}),
},
})),
{
input,
output: {
file: `${output}/${name}.d.ts`,
format: 'esm',
inlineDynamicImports: true,
},
external: defaultExternals,
plugins: [
resolve({
extensions: ['.js', '.ts', '.json', '.node'],
}),
typescript({
emitDeclarationOnly: true,
declaration: true,
declarationDir: `${output}/types`,
tsconfig: path.resolve('./tsconfig.json'),
outputToFilesystem: true,
incremental: false,
include: ['src/**/*.ts'],
exclude: [
'**/*.test.ts',
'**/tests/**/*',
],
}),
...defaultPlugins,
{
writeBundle () {
fs.unlinkSync(`${output}/${name}.d.ts`);
},
},
],
},
{
input: `${output}/types/index.d.ts`,
output: [{ file: `${output}/${name}.d.ts`, format: 'es' }],
external: defaultExternals,
plugins: [
resolve({
extensions: ['.js', '.ts', '.json', '.node'],
}),
dts({ respectExternal: true }),
{
writeBundle () {
fs.rmSync(`${output}/types`, { recursive: true, force: true });
},
},
],
},
];