-
Notifications
You must be signed in to change notification settings - Fork 13
/
rollup.config.ts
93 lines (86 loc) · 2.04 KB
/
rollup.config.ts
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
import { defineConfig } from 'rollup';
import { swc, preserveUseDirective } from 'rollup-plugin-swc3';
import { dts } from 'rollup-plugin-dts';
import fsp from 'node:fs/promises';
import pkgJson from './package.json';
import browserslist from 'browserslist';
import { getEntries } from './tools/get-entries';
const externalModules = Object.keys(pkgJson.dependencies)
.concat(Object.keys(pkgJson.peerDependencies))
.concat([
'react-router-dom',
'next'
]);
function external(id: string) {
return externalModules.some((name) => id === name || id.startsWith(`${name}/`));
}
// Same target as Next.js 13
const targets = browserslist([
'chrome 64',
'edge 79',
'firefox 67',
'opera 51',
'safari 12'
]);
export default async function () {
await fsp.rm('dist', { recursive: true, force: true });
const input = await getEntries();
return defineConfig([{
input,
output: [{
dir: 'dist',
format: 'commonjs',
entryFileNames: '[name]/index.cjs',
chunkFileNames: 'chunks/[name].[hash].cjs',
compact: true
}, {
dir: 'dist',
format: 'commonjs',
entryFileNames: '[name]/index.js',
chunkFileNames: 'chunks/[name].[hash].js',
compact: true
}, {
dir: 'dist',
format: 'esm',
entryFileNames: '[name]/index.mjs',
chunkFileNames: 'chunks/[name].[hash].mjs',
compact: true
}],
plugins: [
swc({
isModule: true,
jsc: {
target: undefined,
transform: {
react: {
runtime: 'automatic'
}
},
minify: {
compress: {
passes: 2,
const_to_let: false
},
mangle: {},
module: true
}
},
minify: true,
env: {
targets
}
}),
preserveUseDirective()
],
external,
cache: true
}, {
input,
output: {
dir: 'dist',
format: 'commonjs',
entryFileNames: '[name]/index.d.ts'
},
plugins: [dts()]
}]);
}