-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrollup.config.js
47 lines (39 loc) · 1.33 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
const preserveDirectives = require("rollup-plugin-preserve-directives");
const terser = require("@rollup/plugin-terser");
const { visualizer } = require("rollup-plugin-visualizer");
const glob = require("fast-glob");
const path = require("node:path");
module.exports = (config) => {
config.preserveModules = true;
const dir = config.input.index.slice(0, -8);
const files = glob.sync("./**/index.{ts,js}", {
cwd: dir,
});
config.input = Object.fromEntries(
files.map((file) => [file.slice(0, -9) || "index", path.join(dir, file)]),
);
// console.log(
// JSON.stringify(
// Object.fromEntries(
// files.map((file) => {
// const filename = file.slice(0, -9);
// const entry = filename || "index";
// const isIndex = filename.length === 0;
// return [
// isIndex ? "." : `./${filename}`,
// {
// types: `${isIndex ? "." : `./${filename}`}/${entry}.esm.d.ts`,
// import: `./${entry}.esm.js`,
// },
// ];
// }),
// ),
// ),
// );
config.plugins.push(
preserveDirectives.default(), // For preserving "use client" directives
visualizer(), // For visualizing bundle size
terser(), // For minification
);
return config;
};