-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathelectron.vite.config.js
More file actions
122 lines (120 loc) · 3.58 KB
/
Copy pathelectron.vite.config.js
File metadata and controls
122 lines (120 loc) · 3.58 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
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
import { builtinModules } from "node:module";
import { resolve } from "node:path";
import react from "@vitejs/plugin-react";
import { defineConfig } from "electron-vite";
import sassDts from "vite-plugin-sass-dts";
import { globalExternals } from "./build/global-externals.js";
// Modules provided by the Node.js/Electron runtime in the Freelens host. They
// must stay external (left as `require(...)`) instead of being bundled. We list
// them explicitly because setting `rolldownOptions` opts out of the
// `rollupOptions.external` that electron-vite would otherwise apply.
const runtimeExternals = ["electron", /^electron\//, ...builtinModules, ...builtinModules.map((m) => `node:${m}`)];
export default defineConfig({
// main process has full access to Node.js APIs
main: {
build: {
lib: {
entry: resolve(__dirname, "src/main/index.ts"),
// Freelens 1.xx extensions are CommonJS modules
formats: ["cjs"],
},
rolldownOptions: {
external: runtimeExternals,
output: {
// silence warning about using `chunk.default` to access the default export
exports: "named",
// prefer separate files for each module
preserveModules: (process.env.VITE_PRESERVE_MODULES ?? "true") === "true",
preserveModulesRoot: "src/main",
},
},
sourcemap: true,
},
oxc: {
decorator: {
legacy: true,
emitDecoratorMetadata: true,
},
},
plugins: [
react({
babel: {
plugins: [
[
"@babel/plugin-proposal-decorators",
{
version: "2023-05",
},
],
],
},
}),
globalExternals({
// the modules are provided by the host app as a global variable
"@freelensapp/extensions": "global.LensExtensions",
mobx: "global.Mobx",
}),
],
},
// renderer process in Freelens can use Node.js modules then it is configured
// with settings for preload script
preload: {
build: {
lib: {
entry: resolve(__dirname, "src/renderer/index.tsx"),
// Freelens 1.xx extensions are CommonJS modules
formats: ["cjs"],
},
outDir: "out/renderer",
rolldownOptions: {
external: runtimeExternals,
output: {
// silence warning about using `chunk.default` to access the default export
exports: "named",
// prefer separate files for each module
preserveModules: (process.env.VITE_PRESERVE_MODULES ?? "true") === "true",
preserveModulesRoot: "src/renderer",
},
},
sourcemap: true,
},
css: {
modules: {
localsConvention: "camelCaseOnly",
},
},
oxc: {
decorator: {
legacy: true,
emitDecoratorMetadata: true,
},
},
plugins: [
sassDts({
enabledMode: ["development", "production"],
}),
react({
babel: {
plugins: [
[
"@babel/plugin-proposal-decorators",
{
version: "2023-05",
},
],
],
},
}),
globalExternals({
// the modules are provided by the host app as a global variable
"@freelensapp/extensions": "global.LensExtensions",
mobx: "global.Mobx",
"mobx-react": "global.MobxReact",
react: "global.React",
"react-dom": "global.ReactDom",
"react-router-dom": "global.ReactRouterDom",
"react/jsx-runtime": "global.ReactJsxRuntime",
}),
],
},
});