forked from repeaterjs/repeater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
81 lines (73 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
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
import fs from "fs";
import path from "path";
import ts from "rollup-plugin-typescript2";
import MagicString from "magic-string";
import { transform } from "ts-transform-import-path-rewrite";
import pkg from "./package.json";
/** A hack to provide package.json files with "type": "commonjs" in cjs/umd subdirectories. */
function cjs() {
return {
name: "cjs",
writeBundle({ dir, format }) {
fs.writeFileSync(
path.join(__dirname, dir, "package.json"),
JSON.stringify(
{
name: `${pkg.name}-${format}`,
type: "commonjs",
private: true,
},
null,
2,
),
);
},
};
}
/** 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 = "./" + 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;
},
};
}
/** A hack to rewrite import paths in d.ts files for deno. */
function transformer() {
const rewritePath = transform({
rewrite(importPath) {
return importPath + ".js";
},
});
return { afterDeclarations: [rewritePath] };
}
export default [
{
input: "./src/eventual.ts",
output: {
format: "esm",
dir: "./",
sourcemap: true,
chunkFileNames: "dist/[hash].js",
},
plugins: [ts({ clean: true, transformers: [transformer] }), dts()],
},
{
input: "./src/eventual.ts",
output: {
format: "cjs",
dir: "cjs",
sourcemap: true,
},
plugins: [ts(), cjs()],
},
];