-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrollup.config.cjs
46 lines (39 loc) · 1.34 KB
/
rollup.config.cjs
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
const commonjs = require("@rollup/plugin-commonjs");
const { nodeResolve } = require("@rollup/plugin-node-resolve");
const typescriptPlugin = require("rollup-plugin-typescript2");
const pkg = require("./package.json");
const roots = ["kong/index.ts"];
const formats = ["cjs", "esm", "es"];
const plugins = [typescriptPlugin(), nodeResolve(), commonjs()];
// e.g. lastPartOfPath("foo/bar/baz") -> "baz"
function lastPartOfPath(path) {
const index = path.lastIndexOf("/");
return path.slice(index + 1);
}
// e.g. firstPartOfPath("foo/bar/baz") -> "foo"
function firstPartOfPath(path) {
const index = path.indexOf("/");
return path.slice(0, index);
}
// Returns true for any dependency listed in package.json and for any member of
// roots other than index.js, where roots is the array defined above.
const isExternalModule = (() => {
const deps = new Set(Object.keys(pkg.dependencies ?? {}));
const subrootEndings = new Set(roots.map(lastPartOfPath));
return (id) =>
deps.has(id) ||
(id.startsWith(".") && subrootEndings.has(lastPartOfPath(id)));
})();
function makeConfig(root) {
return {
input: `src/${root}`,
output: formats.map((format) => ({
dir: `dist/${format}/${firstPartOfPath(root)}`,
format,
sourcemap: true,
})),
external: isExternalModule,
plugins,
};
}
module.exports = roots.map(makeConfig);