forked from SukkaW/foxact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.ts
87 lines (79 loc) · 1.87 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
import { defineConfig } from 'rollup';
import { swc, preserveUseDirective } from 'rollup-plugin-swc3';
import dtsExports from 'rollup-plugin-dts';
import fse from 'fs-extra';
import pkgJson from './package.json';
import browserslist from 'browserslist';
import { getEntries } from './tools/get-entries';
// @ts-expect-error -- rollup-plugin-dts has incorrect types
const dts = dtsExports.default as typeof dtsExports;
const externalModules = Object.keys(pkgJson.dependencies)
.concat(Object.keys(pkgJson.peerDependencies))
.concat([
'react-router-dom'
]);
const 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 fse.rm('dist', { recursive: true, force: true });
const input = await getEntries();
return defineConfig([{
input,
output: [{
dir: 'dist',
format: 'commonjs',
entryFileNames: '[name]/index.cjs'
}, {
dir: 'dist',
format: 'commonjs',
entryFileNames: '[name]/index.js'
}, {
dir: 'dist',
format: 'esm',
entryFileNames: '[name]/index.mjs'
}],
plugins: [
swc({
isModule: true,
jsc: {
transform: {
react: {
runtime: 'automatic'
}
},
minify: {
compress: {
passes: 2
},
mangle: {},
module: true
}
},
minify: true,
env: {
targets
}
}),
preserveUseDirective()
],
external,
cache: true
}, {
input,
output: {
dir: 'dist',
format: 'commonjs',
entryFileNames: '[name]/index.d.ts'
},
plugins: [dts()]
}]);
}