Skip to content

Commit 49dd970

Browse files
committed
build web for electron forge
1 parent 488a6f1 commit 49dd970

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"build-web": "npm run clean-web && tsc --noEmit && vite build --config ./vite.config.ts",
1919
"build-electron-html": "npm run clean-electron && tsc --noEmit && vite build --emptyOutDir --config ./vite.config.electron.ts",
2020
"watch-electron-html": "npm run clean-electron && tsc --noEmit && vite build --emptyOutDir --watch --config ./vite.config.electron.ts",
21+
"build-electron-forge-html": "npm run clean-electron && tsc --noEmit && vite build --emptyOutDir --config ./vite.config.electron-forge.ts",
2122
"build-all": "npm run build-web && npm run build-electron-html",
2223
"upload-production": "gsutil -m cp -r ../dist/web/* gs://dicekeys.app/ && gsutil setmeta -h cache-control:no-store gs://dicekeys.app/index.html & gsutil -m setmeta -h \"Content-Type: application/javascript\" gs://dicekeys.app/assets/*.js",
2324
"update-production": "npm run build-web & npm run upload-production",

web/vite.config.electron-forge.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { defineConfig } from "vite";
2+
import react from "@vitejs/plugin-react";
3+
import { resolve } from "path";
4+
5+
// https://vitejs.dev/config/
6+
export default defineConfig({
7+
plugins: [react()],
8+
root: "./src/",
9+
// FOR ELECTRON ONLY, set the base to empty string so that assets are read from relative path
10+
// IMPORTANT: never do this for the web version of the app (vite.config.ts)
11+
// as that app changes the window location (eg. /E3/secret) which
12+
// will break all relative paths.
13+
// (may the three days of debugging in March '22 rest in peace.)
14+
base: "./",
15+
define: {
16+
VITE_BUILD_VERSION: `"${process.env.npm_package_version}"`,
17+
VITE_BUILD_DATE: `"${new Date().toLocaleString('en-us', { year: 'numeric', month: 'short', day: 'numeric' })}"`,
18+
VITE_SET_APP_RUNNING_IN_ELECTRON: true
19+
},
20+
build: {
21+
// Do not minify for Electron
22+
minify: false,
23+
// Required for dependency on BigInt and number literals ending in n (1n)
24+
target: "es2020",
25+
// Write directly into the electron subdirectory
26+
outDir: "../../electron-forge/electron-html/",
27+
// We love source maps for debugging, and since we're open source, there's no reason to hide 'em.
28+
sourcemap: "inline",
29+
30+
// Compile the electron.html file as the root
31+
rollupOptions: {
32+
input: {
33+
main: resolve(__dirname, './src/electron.html'),
34+
}
35+
},
36+
}
37+
})

0 commit comments

Comments
 (0)