- Bump Node.js to version 18. This change is necessary as Node.js v16 will reach end-of-life on 2023-09-11. It also ensure compatibility with dependencies requiring minimum of Node.js v18, such as `vite`, `@vitejs`plugin-legacy` and `icon-gen`. - Bump `setup-node` action to v4. - Recommend using the `nvm` tool for managing Node.js versions in the documentation. - Update documentation to point to code reference for required Node.js version. This removes duplication of information, and keeps the code as single source of truth for required Node.js version. - Refactor code to adopt the `node:` protocol for Node API imports as per Node.js 18 standards. This change addresses ambiguities and aligns with Node.js best practices (nodejs/node#38343). Currently, there is no ESLint rule to enforce this protocol, as noted in import-js/eslint-plugin-import#2717. - Replace `cross-fetch` dependency with the native Node.js fetch API introduced in Node.js 18. Adjust type casting for async iterable read streams to align with the latest Node.js APIs, based on discussions in DefinitelyTyped/DefinitelyTyped#65542.
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import { resolve } from 'node:path';
|
|
import { mergeConfig, UserConfig } from 'vite';
|
|
import { defineConfig, externalizeDepsPlugin } from 'electron-vite';
|
|
import { getAliasesFromTsConfig, getClientEnvironmentVariables } from './vite-config-helper';
|
|
import { createVueConfig } from './vite.config';
|
|
import distDirs from './dist-dirs.json' assert { type: 'json' };
|
|
|
|
const MAIN_ENTRY_FILE = resolvePathFromProjectRoot('src/presentation/electron/main/index.ts');
|
|
const PRELOAD_ENTRY_FILE = resolvePathFromProjectRoot('src/presentation/electron/preload/index.ts');
|
|
const WEB_INDEX_HTML_PATH = resolvePathFromProjectRoot('src/presentation/index.html');
|
|
const ELECTRON_DIST_SUBDIRECTORIES = {
|
|
main: resolveElectronDistSubdirectory('main'),
|
|
preload: resolveElectronDistSubdirectory('preload'),
|
|
renderer: resolveElectronDistSubdirectory('renderer'),
|
|
};
|
|
|
|
process.env.ELECTRON_ENTRY = resolve(ELECTRON_DIST_SUBDIRECTORIES.main, 'index.cjs');
|
|
|
|
export default defineConfig({
|
|
main: getSharedElectronConfig({
|
|
distDirSubfolder: ELECTRON_DIST_SUBDIRECTORIES.main,
|
|
entryFilePath: MAIN_ENTRY_FILE,
|
|
}),
|
|
preload: getSharedElectronConfig({
|
|
distDirSubfolder: ELECTRON_DIST_SUBDIRECTORIES.preload,
|
|
entryFilePath: PRELOAD_ENTRY_FILE,
|
|
}),
|
|
renderer: mergeConfig(
|
|
createVueConfig({
|
|
supportLegacyBrowsers: false,
|
|
}),
|
|
{
|
|
build: {
|
|
outDir: ELECTRON_DIST_SUBDIRECTORIES.renderer,
|
|
rollupOptions: {
|
|
input: {
|
|
index: WEB_INDEX_HTML_PATH,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
),
|
|
});
|
|
|
|
function getSharedElectronConfig(options: {
|
|
readonly distDirSubfolder: string;
|
|
readonly entryFilePath: string;
|
|
}): UserConfig {
|
|
return {
|
|
build: {
|
|
outDir: options.distDirSubfolder,
|
|
lib: {
|
|
entry: options.entryFilePath,
|
|
},
|
|
rollupOptions: {
|
|
output: {
|
|
entryFileNames: '[name].cjs', // This is needed so `type="module"` works
|
|
},
|
|
},
|
|
},
|
|
plugins: [externalizeDepsPlugin()],
|
|
define: {
|
|
...getClientEnvironmentVariables(),
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
...getAliasesFromTsConfig(),
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
function resolvePathFromProjectRoot(pathSegment: string): string {
|
|
return resolve(__dirname, pathSegment);
|
|
}
|
|
|
|
function resolveElectronDistSubdirectory(subDirectory: string): string {
|
|
const electronDistDir = resolvePathFromProjectRoot(distDirs.electronUnbundled);
|
|
return resolve(electronDistDir, subDirectory);
|
|
}
|