-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.mjs
92 lines (88 loc) · 2.07 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
import { readFileSync, rmSync, writeFileSync } from "fs"
import commonjs from "@rollup/plugin-commonjs"
import { defineConfig } from "rollup"
import dts from "rollup-plugin-dts"
import json from "@rollup/plugin-json"
import nodeResolve from "@rollup/plugin-node-resolve"
import path from "path"
import typescript from "rollup-plugin-typescript2"
const name = path.basename(path.resolve("."))
const pkg = JSON.parse(readFileSync("./package.json").toString())
const external = [
...Object.keys(pkg.dependencies || {}),
"fs",
"path",
"vite",
"rollup",
"webpack",
"typescript",
"@swc/core",
"@macro-plugin/core"
]
/**
* @returns {import("rollup").OutputOptions[]}
*/
function createOutput () {
return [
{
file: "dist/index.js",
format: "cjs",
},
{
file: "dist/index.mjs",
format: "es",
}
]
}
export default defineConfig([
{
input: "./src/index.ts",
output: createOutput(),
plugins: [
{
name: "del",
transform (code, id) {
if (id.endsWith(".cts") || id.endsWith(".mts")) return ""
},
buildStart () {
rmSync("./dist", { recursive: true, force: true })
}
},
json(),
nodeResolve(),
commonjs(),
typescript({
tsconfigOverride: {
include: ["packages/**/src"]
}
})
],
onwarn (warning, warn) {
if (warning.code === "CIRCULAR_DEPENDENCY") return
warn(warning)
},
external
},
{
input: `./dist/packages/${name}/src/index.d.ts`,
output: [{
file: "dist/index.d.ts",
format: "es"
}],
plugins: [
dts({ respectExternal: true }),
{
name: "del",
buildEnd () {
rmSync("./dist/packages", { recursive: true, force: true })
},
closeBundle () {
if (name === "shared") {
writeFileSync("./dist/index.d.ts", readFileSync("./dist/index.d.ts").toString().replace("const scan: typeof scan;", "").replace("const constants: typeof constants;", ""))
}
}
}
],
external
}
])