-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
95 lines (87 loc) · 1.83 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
import * as fs from "fs";
import * as path from "path";
import typescript2 from "rollup-plugin-typescript2";
import MagicString from "magic-string";
/**
* 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;
},
};
}
import pkg from "./package.json";
function copyPackage() {
return {
name: "copy-stuff",
writeBundle() {
const pkg1 = {...pkg};
delete pkg1.private;
delete pkg1.scripts;
delete pkg1.typesVersions;
rewriteExports(pkg1.exports);
fs.writeFileSync("./dist/package.json", JSON.stringify(pkg1, null, 2));
fs.copyFileSync("./README.md", "./dist/README.md");
},
};
}
function rewriteExports(exports) {
for (const key of Object.keys(exports)) {
if (typeof exports[key] === "object") {
rewriteExports(exports[key]);
} else {
exports[key] = exports[key].replace(
new RegExp(`^.${path.sep}dist${path.sep}`),
`.${path.sep}`,
);
}
}
}
const input = [
"src/edit.ts",
"src/contentarea.ts",
"src/keyer.ts",
"src/history.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],
},
];