-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.base.config.mjs
50 lines (43 loc) · 1.43 KB
/
rollup.base.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
import fs from "fs";
import path from "path";
import typescript from "rollup-plugin-typescript2";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
const isProd = process.env.NODE_ENV === "production";
export const external = ["react", "react-dom"];
export const createConfig = (input, output, additionalPlugins = []) => ({
input,
output,
plugins: [...plugins, ...additionalPlugins],
external,
});
export const plugins = [
peerDepsExternal(),
resolve(),
commonjs(),
typescript({ tsconfig: "./tsconfig.json", useTsconfigDeclarationDir: true }),
isProd && terser(),
].filter(Boolean);
export const createBuildsForFolder = (folderPath, outputFolder) => {
const isDirectory = (source) => fs.lstatSync(source).isDirectory();
const getDirectories = (source) =>
fs
.readdirSync(source)
.map((name) => path.join(source, name))
.filter(isDirectory);
const folders = getDirectories(folderPath);
return folders.map((folder) => {
const nameFileModule = path.basename(folder).toLowerCase();
return createConfig(
`${folder}/index.ts`,
["cjs", "esm"].map((format) => ({
file: `dist/${outputFolder}/${nameFileModule}/${nameFileModule}.${format}.js`,
format,
sourcemap: true,
exports: "named",
}))
);
});
};