-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
127 lines (116 loc) · 3.6 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* eslint-disable header/header */
import { defineConfig } from "rollup";
import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import replace from "@rollup/plugin-replace";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
import json from "@rollup/plugin-json";
import scss from "rollup-plugin-scss";
import swc from "@rollup/plugin-swc";
import path from "path";
import fs from "fs";
const dirname = path.dirname(new URL(import.meta.url).pathname);
let dist = path.join(dirname, "dist").replaceAll("%20", "");
if (process.platform === "win32") {
dist = dist.replace(/^\\/g, "");
}
if (!fs.existsSync(path.join(dist, "package.json"))) {
if (!fs.existsSync(dist)) {
fs.mkdirSync(dist);
}
fs.writeFileSync(
path.join(dist, "package.json"),
JSON.stringify({
module: "commonjs",
main: "./main.js",
})
);
}
const isProduction = process.env.ROLLUP_WATCH !== "true";
export default defineConfig([
{
input: "packages/main/index.ts",
output: {
format: "cjs",
file: "dist/main.js",
},
plugins: [
nodeResolve({
exportConditions: ["node"],
}),
typescript(),
commonjs(),
json(),
isProduction && terser(),
].filter(Boolean),
external: ["electron", "original-fs"],
},
{
input: "packages/preload/index.ts",
output: {
format: "cjs",
file: "dist/preload.js",
},
plugins: [
nodeResolve({
exportConditions: ["node"],
}),
typescript(),
commonjs({
ignoreDynamicRequires: true,
}),
json(),
replace({
preventAssignment: true,
values: {
"process.env.AERO_CHANNEL": process.argv.includes("--preview")
? JSON.stringify("preview")
: !isProduction
? JSON.stringify("development")
: JSON.stringify("production"),
},
}),
isProduction && terser(),
].filter(Boolean),
external: ["electron", "original-fs"],
},
{
input: "packages/renderer/index.ts",
output: {
format: "cjs",
file: "dist/renderer.js",
},
plugins: [
nodeResolve({
exportConditions: ["node"],
extensions: [".js", ".jsx", ".ts", ".tsx"],
}),
scss({
fileName: "renderer.css",
outputStyle: "compressed",
}),
commonjs(),
json(),
swc(),
{
version: "0.0.1",
name: "plugin-filecontent",
resolveId(source) {
if (source.startsWith("~content/")) {
return source.replace("~content/", "_LOAD_CONTENT_/");
}
},
load(id) {
if (id.startsWith("_LOAD_CONTENT_/")) {
const file = fs.readFileSync(id.replace("_LOAD_CONTENT_/", ""), "utf-8");
return `export default ${JSON.stringify(file)}`;
}
},
},
typescript(),
isProduction && terser(),
].filter(Boolean),
external: ["electron", "react", "original-fs"],
},
]);