-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathrollup.config.js
57 lines (51 loc) · 1.98 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
import typescript from "@rollup/plugin-typescript";
import { basename, join } from "path";
import dts from "rollup-plugin-dts";
import { rollupImportMapPlugin } from "rollup-plugin-import-map";
import { dependencies } from "./package.json";
const BUILD_PATH = join("builds", "deno");
const DEFINITION_FILE_NAME = "index.d.ts";
const DEFINITION_FILE_PATH = join(BUILD_PATH, DEFINITION_FILE_NAME);
const COMMONJS_FILE_NAME = "index.js";
const COMMONJS_FILE_PATH = join(BUILD_PATH, COMMONJS_FILE_NAME);
const ESM_FILE_NAME = "index.mjs";
const ESM_FILE_PATH = join(BUILD_PATH, ESM_FILE_NAME);
const BUNDLED_SOURCE_INPUT_PATH = join("lib", "types", "index.d.ts");
const SOURCE_INPUT_PATH = join("src", "index.ts");
const REFERENCE_COMMENT = `/// <reference types="./${DEFINITION_FILE_NAME}"/>\n`;
// as it currently stands, all skypack plugins for rollup do not support scoped imports (e.g. @types/*)
// nor do they support a ?dts query string suffix to the url, which is necessary for deno
// import maps are a great substitute for such a plugin, and they offer more flexibility
const imports = {};
for (const [dep, ver] of Object.entries(dependencies)) {
imports[basename(dep)] = `https://cdn.skypack.dev/${dep}@${ver}?dts`;
}
const config = [
{
// Using bundled path to not have to deal with absolute paths transpilation
input: BUNDLED_SOURCE_INPUT_PATH,
output: [{ file: DEFINITION_FILE_PATH, format: "es" }],
plugins: [rollupImportMapPlugin([{ imports }]), dts()],
},
{
input: SOURCE_INPUT_PATH,
output: [
{ file: COMMONJS_FILE_PATH, format: "cjs", banner: REFERENCE_COMMENT },
],
plugins: [
typescript({
compilerOptions: { lib: ["es5", "es6", "dom"], target: "es5" },
}),
],
},
{
input: SOURCE_INPUT_PATH,
output: [{ file: ESM_FILE_PATH, format: "es", banner: REFERENCE_COMMENT }],
plugins: [
typescript({
compilerOptions: { lib: ["es5", "es6", "dom"], target: "es5" },
}),
],
},
];
export default config;