bolt.diy/vite-electron.config.ts
Derek Wang 1ce6ad6b59
Some checks failed
Docker Publish / docker-build-publish (push) Has been cancelled
Update Stable Branch / prepare-release (push) Has been cancelled
feat: electron desktop app without express server (#1136)
* feat: add electron app

* refactor: using different approach

* chore: update commit hash to 02621e3545

* fix: working dev but prod showing not found and lint fix

* fix: add icon

* fix: resolve server file load issue

* fix: eslint and prettier wip

* fix: only load server build once

* fix: forward request for other ports

* fix: use cloudflare {} to avoid crash

* fix: no need for appLogger

* fix: forward cookie

* fix: update script and update preload loading path

* chore: minor update for appId

* fix: store and load all cookies

* refactor: split main/index.ts

* refactor: group electron main files into two folders

* fix: update electron build configs

* fix: update auto update feat

* fix: vite-plugin-node-polyfills need to be in dependencies for dmg version to work

* ci: trigger build for electron branch

* ci: mark draft if it's from branch commit

* ci: add icons for windows and linux

* fix: update icons for windows

* fix: add author in package.json

* ci: use softprops/action-gh-release@v2

* fix: use path to join

* refactor: refactor path logic for working in both mac and windows

* fix: still need vite-plugin-node-polyfills dependencies

* fix: update vite-electron.config.ts

* ci: sign mac app

* refactor: assets folder

* ci: notarization

* ci: add NODE_OPTIONS

* ci: window only nsis dist

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-03-20 00:22:06 +05:30

76 lines
2.0 KiB
TypeScript

import { defineConfig } from 'vite';
import { vitePlugin as remixVitePlugin } from '@remix-run/dev';
import UnoCSS from 'unocss/vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { optimizeCssModules } from 'vite-plugin-optimize-css-modules';
import tsconfigPaths from 'vite-tsconfig-paths';
import { execSync } from 'child_process';
// Get git hash with fallback
const getGitHash = () => {
try {
return execSync('git rev-parse --short HEAD').toString().trim();
} catch {
return 'no-git-info';
}
};
export default defineConfig((config) => {
return {
define: {
__COMMIT_HASH: JSON.stringify(getGitHash()),
__APP_VERSION: JSON.stringify(process.env.npm_package_version),
},
build: {
target: 'esnext',
},
plugins: [
nodePolyfills({
include: ['path', 'buffer', 'process'],
}),
remixVitePlugin({
future: {
v3_fetcherPersist: true,
v3_relativeSplatPath: true,
v3_throwAbortReason: true,
v3_lazyRouteDiscovery: true,
},
serverModuleFormat: 'esm',
}),
UnoCSS(),
tsconfigPaths(),
config.mode === 'production' && optimizeCssModules({ apply: 'build' }),
{
name: 'replaceReactDomServerImport',
enforce: 'pre',
transform(code, id) {
if (id.endsWith('entry.server.tsx')) {
/*
* Hack: fix the issue with react-dom/server not being found in electron
* Replace the import from 'react-dom/server' with 'react-dom/server.browser', only for electron build
*/
return code.replace(/from 'react-dom\/server';?/g, "from 'react-dom/server.browser';");
}
return undefined;
},
},
],
envPrefix: [
'VITE_',
'OPENAI_LIKE_API_BASE_URL',
'OLLAMA_API_BASE_URL',
'LMSTUDIO_API_BASE_URL',
'TOGETHER_API_BASE_URL',
],
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
};
});