Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tech] Move to the electron-vite build tool #3218

Merged
merged 9 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Launch_Heroic.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/vite",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/vite.cmd"
}
"runtimeExecutable": "pnpm",
"args": ["start"]
}
]
}
2 changes: 1 addition & 1 deletion e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type ElectronApplication
} from '@playwright/test'

const main_js = join(__dirname, '../build/electron/main.js')
const main_js = join(__dirname, '../build/main/main.js')

/**
* Helper function to define a test requiring Heroic to be running
Expand Down
75 changes: 75 additions & 0 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react-swc'
import svgr from 'vite-plugin-svgr'
import path from 'path'

import type { Plugin } from 'vite'

const srcAliases = ['backend', 'frontend', 'common'].map((aliasName) => ({
find: aliasName,
replacement: path.join(__dirname, 'src', aliasName)
}))

const dependenciesToNotExternalize = [
'@xhmikosr/decompress',
'@xhmikosr/decompress-targz'
]

// FIXME: Potentially publish this as a dedicated plugin, if other projects
// run into the same issue
const vite_plugin_react_dev_tools: Plugin = {
name: 'react-dev-tools-replace',
transformIndexHtml: {
handler: (html) =>
html.replace(
'<!-- REACT_DEVTOOLS_SCRIPT -->',
'<script src="http://localhost:8097"></script>'
)
}
}

export default defineConfig(({ mode }) => ({
main: {
build: {
rollupOptions: {
input: 'src/backend/main.ts'
},
outDir: 'build/main',
minify: mode === 'production',
sourcemap: mode === 'development' ? 'inline' : false
},
resolve: { alias: srcAliases },
plugins: [externalizeDepsPlugin({ exclude: dependenciesToNotExternalize })]
},
preload: {
build: {
rollupOptions: {
input: 'src/backend/preload.ts'
},
outDir: 'build/preload',
minify: mode === 'production',
sourcemap: mode === 'development' ? 'inline' : false
},
resolve: { alias: srcAliases },
plugins: [externalizeDepsPlugin({ exclude: dependenciesToNotExternalize })]
},
renderer: {
root: '.',
build: {
rollupOptions: {
input: path.resolve('index.html')
},
target: 'esnext',
outDir: 'build',
emptyOutDir: false,
minify: mode === 'production',
sourcemap: mode === 'development' ? 'inline' : false
},
resolve: { alias: srcAliases },
plugins: [
react(),
svgr(),
mode !== 'production' && vite_plugin_react_dev_tools
]
}
}))
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"beta": "Caesar Clown"
},
"private": false,
"main": "build/electron/main.js",
"main": "build/main/main.js",
"homepage": "./",
"license": "GPL-3.0-only",
"description": "An Open Source Launcher for GOG, Epic Games and Amazon Games",
Expand All @@ -22,22 +22,22 @@
"node": ">= 16"
},
"scripts": {
"start": "vite",
"debug:react": "vite & react-devtools",
"start": "electron-vite dev --watch",
"debug:react": "pnpm start & react-devtools",
"codecheck": "tsc --noEmit",
"find-deadcode": "ts-prune --error",
"test": "jest",
"test-watch": "jest --watch --maxWorkers=25%",
"test:ci": "jest --runInBand --silent",
"test:e2e": "vite build && cross-env CI=e2e xvfb-maybe -- playwright test",
"release:linux": "vite build && electron-builder -p always --linux deb AppImage rpm pacman tar.xz",
"release:mac": "vite build && electron-builder -p always --mac --x64 --arm64",
"release:win": "vite build && electron-builder -p always --win portable --x64",
"test:e2e": "electron-vite build && cross-env CI=e2e xvfb-maybe -- playwright test",
"release:linux": "electron-vite build && electron-builder -p always --linux deb AppImage rpm pacman tar.xz",
"release:mac": "electron-vite build && electron-builder -p always --mac --x64 --arm64",
"release:win": "electron-vite build && electron-builder -p always --win portable --x64",
"release:updateFlathub:ci": "tsc flathub/update-flathub.ts --skipLibCheck --target es2015 --moduleResolution node --module commonjs && node flathub/update-flathub.js",
"sign:win": "vite build && electron-builder -p never --win nsis --x64",
"dist:linux": "vite build && electron-builder --linux",
"dist:mac": "export CSC_IDENTITY_AUTO_DISCOVERY=false && vite build && electron-builder --mac",
"dist:win": "vite build && electron-builder --win",
"sign:win": "electron-vite build && electron-builder -p never --win nsis --x64",
"dist:linux": "electron-vite build && electron-builder --linux",
"dist:mac": "export CSC_IDENTITY_AUTO_DISCOVERY=false && electron-vite build && electron-builder --mac",
"dist:win": "electron-vite build && electron-builder --win",
"dist:flatpak": "pnpm dist:linux appimage && pnpm flatpak:prepare && pnpm flatpak:build",
"lint": "eslint --cache --ext .tsx,ts .",
"lint-fix": "eslint --fix --ext .tsx,ts ./src",
Expand Down Expand Up @@ -127,10 +127,11 @@
"@types/tmp": "0.2.3",
"@typescript-eslint/eslint-plugin": "5.47.1",
"@typescript-eslint/parser": "5.47.1",
"@vitejs/plugin-react-swc": "3.2.0",
"@vitejs/plugin-react-swc": "3.6.0",
"cross-env": "7.0.3",
"electron": "github:castlabs/electron-releases#v29.1.3+wvcus",
"electron-builder": "24.13.3",
"electron-vite": "^2.0.0",
"eslint": "8.36.0",
"eslint-config-prettier": "8.7.0",
"eslint-plugin-import": "2.27.5",
Expand All @@ -151,9 +152,8 @@
"typed-emitter": "^2.1.0",
"typescript": "4.9.4",
"unimported": "1.26.0",
"vite": "3.2.8",
"vite-plugin-electron": "0.10.2",
"vite-plugin-svgr": "2.4.0"
"vite": "5.2.8",
"vite-plugin-svgr": "4.2.0"
},
"resolutions": {
"ts-morph": "17.0.1"
Expand Down
Loading
Loading