-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
rollup.config.mjs
187 lines (183 loc) · 4.34 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import typescript from "@rollup/plugin-typescript";
import terser from "@rollup/plugin-terser";
import { babel, getBabelOutputPlugin } from "@rollup/plugin-babel";
import banner from "rollup-plugin-banner2";
import path from "node:path";
import pkg from "./package.json" with { type: "json" };
import vueJsx from "unplugin-vue-jsx/rollup";
import vueVNodePlugin from "./scripts/babel-plugin-annotate-vue-vnode.mjs";
import { svelteCopy } from "./scripts/rollup-plugin-svelte-copy.mjs";
const external = (id) =>
[
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {}),
].some((d) => id.startsWith(d));
const terserPlugin = ({ core, vue } = {}) =>
terser({
ecma: 2018,
module: true,
compress: { passes: 5, unsafe: true, keep_fargs: false },
mangle: {
properties: {
// @vue/babel-plugin-jsx may generate _ field
regex: core ? "^_.+" : "^[$_].+",
...(vue && {
// [Vue warn]: Invalid prop name: "$" is a reserved property.
reserved: ["$"],
}),
},
},
format: {
preserve_annotations: true,
},
});
const corePath = "./lib/core/index.js";
/** @type { import('rollup').RollupOptions[] } */
export default [
// react and type
{
input: "src/index.ts",
output: [
{
file: pkg.main,
format: "cjs",
sourcemap: true,
},
{
file: pkg.module,
format: "es",
sourcemap: true,
},
],
plugins: [
typescript({
tsconfig: "./tsconfig.json",
outDir: ".",
declaration: true,
exclude: ["**/*.{spec,stories}.*"],
}),
getBabelOutputPlugin({
plugins: ["@babel/plugin-transform-react-pure-annotations"],
}),
terserPlugin(),
banner(() => '"use client";\n'),
],
external,
},
// vue
{
input: "src/vue/index.ts",
output: [
{
file: pkg.exports["./vue"].default,
format: "cjs",
sourcemap: true,
},
{
file: pkg.exports["./vue"].import,
format: "es",
sourcemap: true,
},
],
plugins: [
typescript({
tsconfig: "./tsconfig.json",
outDir: ".",
// declaration: true,
exclude: ["**/*.{spec,stories}.*"],
jsx: "preserve",
}),
vueJsx({ optimize: true }),
getBabelOutputPlugin({
plugins: [vueVNodePlugin],
}),
terserPlugin({ vue: true }),
],
external,
},
// solid
{
input: "src/solid/index.ts",
output: [
{
file: pkg.exports["./solid"].default,
format: "cjs",
sourcemap: true,
},
{
file: pkg.exports["./solid"].import,
format: "es",
sourcemap: true,
},
],
plugins: [
typescript({
tsconfig: "./tsconfig.json",
outDir: ".",
// declaration: true,
exclude: ["**/*.{spec,stories}.*"],
jsx: "preserve",
}),
babel({
babelrc: false,
configFile: false,
extensions: [".jsx", ".tsx"],
babelHelpers: "bundled",
presets: ["babel-preset-solid"],
parserOpts: { sourceType: "module", plugins: ["jsx", "typescript"] },
}),
terserPlugin(),
],
external,
},
// solid (for SSR)
{
input: "src/solid/index.ts",
output: [
{
file: pkg.exports["./solid"].solid,
format: "es",
sourcemap: true,
},
],
jsx: "preserve",
// FIXME: props._resizer call inside ListItem is unexpectedly treeshaked by rollup.
treeshake: false,
plugins: [
typescript({
tsconfig: "./tsconfig.json",
outDir: ".",
// declaration: true,
exclude: ["**/*.{spec,stories}.*"],
jsx: "preserve",
}),
// terserPlugin(),
],
external,
},
// svelte
{
input: "src/core/index.ts",
output: [
{
file: corePath,
format: "esm",
// sourcemap: true,
},
],
plugins: [
typescript({
tsconfig: "./tsconfig.json",
outDir: ".",
// declaration: true,
exclude: ["**/*.{spec,stories}.*"],
}),
terserPlugin({ core: true }),
svelteCopy({
dir: path.dirname(pkg.exports["./svelte"].default),
coreDts: path.join(path.dirname(corePath), "index.d.ts"),
}),
],
external,
},
];