-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
80 lines (73 loc) · 1.89 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// @ts-check
import { readFileSync, readdirSync } from "node:fs"
import { getPathAlias, isProduction } from "./src/lib/util/node.js"
import alias from "@rollup/plugin-alias"
import commonjs from "@rollup/plugin-commonjs"
import { nodeResolve } from "@rollup/plugin-node-resolve"
import swc from "@rollup/plugin-swc"
import { defineConfig } from "rollup"
const pkg = JSON.parse(readFileSync("./package.json").toString())
const tsconfig = JSON.parse(
readFileSync("./tsconfig.json", { encoding: "utf-8" })
)
const banner = (/** @type {string} */ name) =>
`
/*!
* ${name} v${pkg.version} (${pkg.homepage})
* Copyright 2022-${new Date().getFullYear()} ${pkg.author}
* Licensed under ${pkg.license}
*
* This file is automatically generated, please do not change it.
*/
`.trim()
// @ts-ignore
function createConfig({ src, dest, name: _name }) {
const name = `${pkg.name}${_name ? `-${_name}` : ""}.js`
return defineConfig({
// @ts-ignore
name,
input: src,
output: {
file: dest,
format: "es",
sourcemap: true,
strict: true,
interop: "auto",
banner: banner(name),
},
plugins: [
swc({
swc: {
minify: isProduction(),
},
}),
alias({
entries: getPathAlias(tsconfig.compilerOptions, import.meta),
}),
commonjs(),
nodeResolve({
extensions: [".js", ".ts"],
}),
],
})
}
export default readdirSync("./src/script", { withFileTypes: true }).map(
(dirent) => {
const parentPath = dirent.parentPath
const name = dirent.name
if (dirent.isFile()) {
return createConfig({
src: `${parentPath}/${name}`,
dest: `./dist/${name}`,
name: name.split(".")[0],
})
}
if (dirent.isDirectory()) {
return createConfig({
src: `${parentPath}/${name}/index.ts`,
dest: `./dist/${name}.js`,
name,
})
}
}
)