-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
rollup.config.base.js
93 lines (84 loc) · 2.01 KB
/
rollup.config.base.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
import resolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import ts from "@wessberg/rollup-plugin-ts";
import * as path from "path";
import { terser } from "rollup-plugin-terser";
function getOutputs(pkg, subpath) {
return [
{
file: pkg.exports[subpath].import,
format: "esm",
},
{
file: pkg.exports[subpath].require,
format: "cjs",
externalLiveBindings: false,
},
];
}
const tsPlugin = ts({
transpiler: "babel",
cwd: path.join(__dirname, "../.."),
tsconfig: path.join(__dirname, "tsconfig.json"),
});
export function getMainEntries(pkg, env) {
const nodeOutputs = getOutputs(pkg, ".");
if (env === "development") {
nodeOutputs.forEach((output) => {
// eslint-disable-next-line no-param-reassign
output.file = output.file.replace(".min.", ".");
});
} else {
nodeOutputs.forEach((output) => {
// eslint-disable-next-line no-param-reassign
output.plugins = [
// Minify only in production
terser({
output: {
// Preserve triple-slash directives
comments: /^\//,
},
}),
];
});
}
const denoOutputFile = nodeOutputs[0].file.replace(
"dist-node/esm/bundle",
`dist-deno/bundle.${env === "development" ? "dev" : "prod"}`,
);
const denoOutput = {
...nodeOutputs[0],
file: denoOutputFile,
banner: `/// <reference types="./${denoOutputFile
.split("/")
.slice(-1)[0]
.replace(".mjs", ".d.ts")}" />`,
};
const commonLastPlugins = [resolve({ browser: true })];
const nodeEntry = {
input: "./src/index.ts",
output: nodeOutputs,
plugins: [tsPlugin, ...commonLastPlugins],
external: [/^@babel\/runtime\//],
};
const denoEntry = {
...nodeEntry,
output: denoOutput,
plugins: [
tsPlugin,
replace({
"process.env.NODE_ENV": JSON.stringify(env),
"typeof window": "typeof document",
}),
...commonLastPlugins,
],
};
return [nodeEntry, denoEntry];
}
export function getServerEntry(pkg, options) {
return {
...options,
output: getOutputs(pkg, "./server"),
plugins: tsPlugin,
};
}