Repository navigation
Expand file tree
/
Copy pathrollup.config.js
More file actions
78 lines (74 loc) · 1.92 KB
/
Copy pathrollup.config.js
File metadata and controls
78 lines (74 loc) · 1.92 KB
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
import json from "@rollup/plugin-json";
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import dts from "rollup-plugin-dts";
import fs from "fs";
import path from "path";
const forgeDir = "external/Iridium-Forge";
const copyForge = {
name: "copy-forge",
writeBundle({ file }) {
const outDir = path.dirname(file);
const wrapper = fs.readFileSync(path.join(forgeDir, "forge.cjs"), "utf8");
const match = wrapper.match(/require\(["'](.+\.node)["']\)/);
if (!match) this.error(`Cannot find .node path in ${forgeDir}/forge.cjs`);
const binary = path.join(forgeDir, match[1]);
if (!fs.existsSync(binary)) {
this.error(`${binary} not found; build Iridium-Forge first`);
}
const name = path.basename(binary);
fs.copyFileSync(binary, path.join(outDir, name));
fs.writeFileSync(
path.join(outDir, "forge.cjs"),
`module.exports = require("./${name}");\n`,
);
},
};
export default [
// ESM JavaScript output
{
input: "iridium.ts",
output: {
file: "dist/iridium.js",
format: "esm",
sourcemap: true,
},
external: [
"fs",
"path",
"os",
"module", // REQUIRED: for createRequire in forge.ts
/\.node$/, // REQUIRED: keeps the binary file external
],
plugins: [
copyForge,
json(),
resolve({
exportConditions: ["node"], // Helps resolve the # imports
}),
commonjs(),
typescript({
tsconfig: "./tsconfig.json",
exclude: [
"playground/**",
"classes/builder/IridiumHelpers/**",
"classes/worker/**",
],
}),
],
},
// Type declarations
{
input: "iridium.ts",
output: {
file: "dist/iridium.d.ts",
format: "es",
},
plugins: [
dts({
exclude: ["playground/**"],
}),
],
},
];