-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
51 lines (45 loc) · 1.8 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
import babelPresetTypescript from "@babel/preset-typescript"
import babel from "@rollup/plugin-babel"
import commonJS from "@rollup/plugin-commonjs"
import json from "@rollup/plugin-json"
import nodeResolve from "@rollup/plugin-node-resolve"
import { findFiles } from "@samual/lib/findFiles"
import babelPluginHere from "babel-plugin-here"
import { readFile } from "fs/promises"
/** @typedef {import("rollup").RollupOptions} RollupOptions */
const SOURCE_FOLDER = "src"
/** @type {(command: Record<string, unknown>) => Promise<RollupOptions>} */
export default async () => {
const [ foundFiles, packageJsonString ] =
await Promise.all([ findFiles(SOURCE_FOLDER), readFile("package.json", { encoding: "utf8" }) ])
const packageJson = JSON.parse(packageJsonString)
const externalDependencies = [
..."dependencies" in packageJson ? Object.keys(packageJson.dependencies) : [],
..."optionalDependencies" in packageJson ? Object.keys(packageJson.optionalDependencies) : []
]
return {
input: Object.fromEntries(
foundFiles.filter(path => path.endsWith(".ts") && !path.endsWith(".d.ts") && !path.endsWith(".test.ts"))
.map(path => [ path.slice(SOURCE_FOLDER.length + 1, -3), path ])
),
output: { dir: "dist", interop: "auto", sourcemap: "inline" },
plugins: [
babel({
babelHelpers: "bundled",
extensions: [ ".ts" ],
presets: [
[ babelPresetTypescript, { allowDeclareFields: true, optimizeConstEnums: true } ]
],
plugins: [ babelPluginHere() ]
}),
commonJS(),
json({ preferConst: true }),
nodeResolve({ extensions: [ ".ts" ] })
],
external: source =>
externalDependencies.some(dependency => source == dependency || source.startsWith(`${dependency}/`)),
preserveEntrySignatures: "allow-extension",
treeshake: { moduleSideEffects: false },
strictDeprecations: true
}
}