electron-vite
Electron + Vite + React + TS
npm create vite@latest vite-and-capacitor --template react-ts
- When run locally the web server, Vite will be in dev mode.
- When create the web build, Vite will be in web mode.
- When create the android build, Vite will be in android mode.
- electron-vite environment variables must following the following schema:
- Main env:
MAIN_VITE_<ENV_NAME>=<ENV_VALUE>
- Preload env:PRELOAD_VITE_<ENV_NAME>=<ENV_VALUE>
- Renderer env:RENDERER_VITE_<ENV_NAME>=<ENV_VALUE>
VITE_APP_ID=CLIENT ID
VITE_AUTHORITY=https://login.microsoftonline.com/OBJECT ID
VITE_REDIRECT_URI=http://localhost:3000
VITE_GRAPH_ENDPOINT=https://graph.microsoft.com/v1.0/me
VITE_API_URL=
-
.env.development.local
defines the environment variables in dev mode. -
.env.web.local
defines the environment variables in web mode. -
.env.android.local
defines the environment variables in android mode. -
.env.desktop.local
defines the environment variables in desktop mode.
-
Install Android Studio (tested until Flamingo | 2022.2.1) (Optional)
-
It is mandatory to set up the environment variables for the Android build:
$env:Path += ";$env:C:\Users\user\AppData\Local\Android\platform-tools" $env:ANDROID_SDK_ROOT="C:\Users\user\AppData\Local\Android" $env:JAVA_HOME='C:\Program Files\Java\jdk-17'
-
Initialize dev server and Electron app (both use .env.development.local):
npm run dev
-
Build for prod:
npm run build-web
-
Build for android:
npm run build-android
-
Set environment variables:
$env:Path += ";$env:C:\Users\user\AppData\Local\Android\platform-tools" $env:ANDROID_SDK_ROOT="C:\Users\user\AppData\Local\Android" $env:JAVA_HOME='C:\Program Files\Java\jdk-17'
-
Run on android emulator (Android Studio recommended):
npx cap sync npx cap run android
-
Build debug and release bundle:
npm run build-android npx cap sync cd ./android chmod +x gradlew ./gradlew assembleDebug #./gradlew assembleRelease
-
Initialize dev server and Electron app (both use .env.development.local):
npm run dev
-
Open DevTools in Electron (disabled in prod):
Ctrl + Shift + I
```sh
# For windows
npm run build:win
# For macOS
npm run build:mac
# For Linux
npm run build:linux
```
https://ionicframework.com/docs/react/adding-ionic-react-to-an-existing-react-project https://staffordwilliams.com/blog/2023/03/06/ionic-capacitor-vite/ https://ionicframework.com/docs/react/your-first-app/deploying-mobile https://stackoverflow.com/questions/76158436/how-to-implement-azure-active-directory-msal-in-ionic-react-so-it-works-when-t https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-nodejs-desktop