-
Notifications
You must be signed in to change notification settings - Fork 75
/
rollup.config.js
105 lines (97 loc) · 2.04 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import * as fs from "fs";
import * as path from "path";
import typescript2 from "rollup-plugin-typescript2";
import MagicString from "magic-string";
import pkg from "./package.json" assert {type: "json"};
/**
* A hack to add triple-slash references to sibling d.ts files for deno.
*/
function dts() {
return {
name: "dts",
renderChunk(code, info) {
if (info.isEntry) {
const dts = path.join("./", info.fileName.replace(/js$/, "d.ts"));
const ms = new MagicString(code);
ms.prepend(`/// <reference types="${dts}" />\n`);
code = ms.toString();
const map = ms.generateMap({hires: true});
return {code, map};
}
return code;
},
};
}
function rewritePaths(exports) {
for (const [key, value] of Object.entries(exports)) {
if (typeof value === "string") {
exports[key] = value.replace(/^\.\/dist/, ".");
} else if (typeof value === "object" && value !== null) {
rewritePaths(value);
}
}
}
function copyPackage() {
return {
name: "copy-package",
writeBundle() {
const pkg1 = JSON.parse(JSON.stringify(pkg));
delete pkg1.private;
delete pkg1.scripts;
rewritePaths(pkg1.exports);
fs.writeFileSync("./dist/package.json", JSON.stringify(pkg1, null, 2));
fs.copyFileSync("./README.md", "./dist/README.md");
},
};
}
const input = [
"src/crank.ts",
"src/dom.ts",
"src/jsx-runtime.ts",
"src/jsx-tag.ts",
"src/html.ts",
"src/standalone.ts",
];
const ts = typescript2({
clean: true,
tsconfigOverride: {
exclude: ["test"],
},
});
export default [
{
input,
output: {
format: "esm",
dir: "dist",
chunkFileNames: "[hash].js",
sourcemap: true,
exports: "named",
},
plugins: [ts, dts(), copyPackage()],
},
{
input,
output: {
format: "cjs",
dir: "dist",
chunkFileNames: "[hash].cjs",
entryFileNames: "[name].cjs",
sourcemap: true,
exports: "named",
},
plugins: [ts],
},
{
input: "src/umd.ts",
output: {
format: "umd",
dir: "dist",
name: "Crank",
preserveModules: false,
sourcemap: true,
exports: "named",
},
plugins: [ts],
},
];