-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
66 lines (62 loc) · 1.84 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { glob } from "glob";
import { defineConfig } from "rollup";
import path from "path";
import { fileURLToPath } from "url";
import terser from "@rollup/plugin-terser";
import commonjs from "@rollup/plugin-commonjs";
// import pkg from "./package.json" assert { type: "json" };
import typescript from "@rollup/plugin-typescript";
import { readFileSync, readSync } from "fs";
const pkg = JSON.parse(readFileSync(path.resolve(process.cwd(), 'package.json'), "utf-8"));
/**
* @param {Record<string, string>} args
* @returns {Array<import('rollup').RollupOptions>}
*/
function asyncConfig(args) {
const { configProject: project } = args;
// console.log(args);
if (!project) {
throw new Error("Missing project");
}
return defineConfig({
input: Object.fromEntries(
glob
.sync(`./packages/${project}/src/**/*.ts{,x}`)
.filter((path) => !/.+test.+/.test(path))
.map((file) => [
path.relative(
`./packages/${project}/src`,
file.slice(0, file.length - path.extname(file).length)
),
fileURLToPath(new URL(file, import.meta.url)),
])
),
output: {
dir: path.resolve(`./packages/${project}/dist`),
format: "esm",
preserveModules: true,
entryFileNames: "[name].mjs",
sourcemap: true,
},
plugins: [
typescript({
tsconfig: path.resolve(`./packages/${project}/tsconfig.json`),
// compilerOptions: {
// declaration: true,
// declarationDir: path.resolve(`./packages/${project}/dist`),
// },
}),
terser(),
commonjs({ esmExternals: true }),
],
external: [
...Object.keys(pkg.dependencies),
"react/jsx-runtime",
// ...Object.keys(pkg.peerDependencies),
],
treeshake: {
preset: "smallest",
},
});
}
export default asyncConfig;