-
Notifications
You must be signed in to change notification settings - Fork 19
/
rollup.config.mjs
97 lines (93 loc) · 2.49 KB
/
rollup.config.mjs
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
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import nodePolyfills from "rollup-plugin-polyfill-node";
import pkg from "./package.json" with { type: "json" };
import ignore from "rollup-plugin-ignore";
import filesize from "rollup-plugin-filesize";
import fs from "node:fs";
import { fileURLToPath } from "node:url";
/**
* Looking for plugins?
*
* Check: {@link https://github.com/rollup/awesome}
*/
export default [
// Browser
{
input: "src/index.ts",
output: {
inlineDynamicImports: true,
file: pkg.browser,
name: "GolemJs",
sourcemap: true,
format: "es",
},
plugins: [
deleteExistingBundles("dist"),
ignore(["tmp"]),
nodeResolve({ browser: true, preferBuiltins: true }),
commonjs(),
nodePolyfills(),
typescript({ tsconfig: "./tsconfig.json", exclude: ["**/*.test.ts"] }),
terser(),
filesize({ reporter: [sizeValidator, "boxen"] }),
],
},
// NodeJS
{
input: {
"golem-js": "src/index.ts",
"golem-js-experimental": "src/experimental/index.ts",
},
output: {
dir: "dist",
format: "esm",
sourcemap: true,
chunkFileNames: "shared-[hash].mjs",
entryFileNames: "[name].mjs",
},
plugins: [
typescript({ tsconfig: "./tsconfig.json", exclude: ["**/*.test.ts"] }),
filesize({ reporter: [sizeValidator, "boxen"] }),
],
},
{
input: {
"golem-js": "src/index.ts",
"golem-js-experimental": "src/experimental/index.ts",
},
output: {
dir: "dist",
format: "cjs",
sourcemap: true,
chunkFileNames: "shared-[hash].js",
},
plugins: [
typescript({
tsconfig: "./tsconfig.json",
exclude: ["**/*.test.ts"],
module: "ES2020",
}),
filesize({ reporter: [sizeValidator, "boxen"] }),
],
},
];
function deleteExistingBundles(path) {
return {
name: "delete-existing-bundles",
buildStart: () => {
const distDir = fileURLToPath(new URL(path, import.meta.url).toString());
if (fs.existsSync(distDir)) {
fs.rmSync(distDir, { recursive: true });
}
console.log("Deleted " + distDir);
},
};
}
function sizeValidator(options, bundle, { bundleSize }) {
if (parseInt(bundleSize) === 0) {
throw new Error(`Something went wrong while building. Bundle size = ${bundleSize}`);
}
}