Migrate to electron-vite and electron-builder

- Switch from deprecated Vue CLI plugin to `electron-vite` (see
  nklayman/vue-cli-plugin-electron-builder#1982)
- Update main/preload scripts to use `index.cjs` filenames to support
  `"type": "module"`, resolving crash issue (#233). This crash was
  related to Electron not supporting ESM (see electron/asar#249,
  electron/electron#21457).
- This commit completes migration to Vite from Vue CLI (#230).

Structure changes:

- Introduce separate folders for Electron's main and preload processes.
- Move TypeHelpers to `src/` to mark tit as accessible by the rest of
  the code.

Config changes:

- Make `vite.config.ts` reusable by Electron configuration.
- On electron-builder, use `--publish` flag instead of `-p` for clarity.

Tests:

- Add log for preload script loading verification.
- Implement runtime environment sanity checks.
- Enhance logging in `check-desktop-runtime-errors`.
This commit is contained in:
undergroundwires
2023-08-24 20:01:53 +02:00
parent ec98d8417f
commit 75c9b51bf2
43 changed files with 1017 additions and 2600 deletions

View File

@@ -1,6 +1,6 @@
/// <reference types="vitest" />
import { resolve } from 'path';
import { defineConfig } from 'vite';
import { defineConfig, UserConfig } from 'vite';
import legacy from '@vitejs/plugin-legacy';
import vue from '@vitejs/plugin-vue2';
import ViteYaml from '@modyfi/vite-plugin-yaml';
@@ -10,45 +10,53 @@ const WEB_DIRECTORY = resolve(getSelfDirectoryAbsolutePath(), 'src/presentation'
const TEST_INITIALIZATION_FILE = resolve(getSelfDirectoryAbsolutePath(), 'tests/shared/bootstrap/setup.ts');
const NODE_CORE_MODULES = ['os', 'child_process', 'fs', 'path'];
export default defineConfig({
root: WEB_DIRECTORY,
plugins: [
vue(),
ViteYaml(),
legacy(),
],
esbuild: {
supported: {
'top-level-await': true, // Exclude browsers not supporting top-level-await
},
},
define: {
...getClientEnvironmentVariables(),
},
resolve: {
alias: {
...getAliasesFromTsConfig(),
},
},
build: {
rollupOptions: {
// Ensure Node core modules are externalized and don't trigger warnings in browser builds
external: {
...NODE_CORE_MODULES,
export function createVueConfig(options?: {
readonly supportLegacyBrowsers: boolean,
}): UserConfig {
return {
root: WEB_DIRECTORY,
plugins: [
vue(),
ViteYaml(),
...[options?.supportLegacyBrowsers ? legacy() : undefined],
],
esbuild: {
supported: {
'top-level-await': true, // Exclude browsers not supporting top-level-await
},
},
},
server: {
port: 3169,
},
test: {
globals: true,
environment: 'jsdom',
alias: {
...getAliasesFromTsConfig(),
define: {
...getClientEnvironmentVariables(),
},
setupFiles: [
TEST_INITIALIZATION_FILE,
],
},
});
resolve: {
alias: {
...getAliasesFromTsConfig(),
},
},
build: {
rollupOptions: {
// Ensure Node core modules are externalized and don't trigger warnings in browser builds
external: {
...NODE_CORE_MODULES,
},
},
},
server: {
port: 3169,
},
test: {
globals: true,
environment: 'jsdom',
alias: {
...getAliasesFromTsConfig(),
},
setupFiles: [
TEST_INITIALIZATION_FILE,
],
},
};
}
export default defineConfig(createVueConfig({
supportLegacyBrowsers: true,
}));