Skip to content

A local-first personal finance app

:electron: Separate build folders for easier switching between web and electron (#3801)

Michael Clark1e1092e472f0
diff --git a/bin/package-electron b/bin/package-electron
index b827d0015a..8203cc99df 100755
--- a/bin/package-electron
+++ b/bin/package-electron
@@ -36,7 +36,7 @@ fi
yarn workspace loot-core build:node
-yarn workspace @actual-app/web build --mode=desktop
+yarn workspace @actual-app/web build --mode=desktop # electron specific build
yarn workspace desktop-electron update-client
diff --git a/packages/desktop-client/.gitignore b/packages/desktop-client/.gitignore
index f635ae3caa..d00b9758da 100644
--- a/packages/desktop-client/.gitignore
+++ b/packages/desktop-client/.gitignore
@@ -10,6 +10,7 @@ playwright-report
# production
build
+build-electron
build-stats
stats.json
diff --git a/packages/desktop-client/vite.config.mts b/packages/desktop-client/vite.config.mts
index 0f921416be..b61316d3b3 100644
--- a/packages/desktop-client/vite.config.mts
+++ b/packages/desktop-client/vite.config.mts
@@ -15,7 +15,7 @@ const addWatchers = (): Plugin => ({
configureServer(server) {
server.watcher
.add([
- path.resolve('../loot-core/lib-dist/*.js'),
+ path.resolve('../loot-core/lib-dist/electron/*.js'),
path.resolve('../loot-core/lib-dist/browser/*.js'),
])
.on('all', function () {
@@ -109,7 +109,7 @@ export default defineConfig(async ({ mode }) => {
build: {
target: 'es2022',
sourcemap: true,
- outDir: 'build',
+ outDir: mode === 'desktop' ? 'build-electron' : 'build',
assetsDir: 'static',
manifest: true,
assetsInlineLimit: 0,
@@ -148,7 +148,7 @@ export default defineConfig(async ({ mode }) => {
extensions: resolveExtensions,
},
plugins: [
- // Macos electron (desktop) builds do not support PWA
+ // electron (desktop) builds do not support PWA
mode === 'desktop'
? undefined
: VitePWA({
diff --git a/packages/desktop-electron/bin/update-client b/packages/desktop-electron/bin/update-client
index 24da05f6fc..d705152cc6 100755
--- a/packages/desktop-electron/bin/update-client
+++ b/packages/desktop-electron/bin/update-client
@@ -4,7 +4,7 @@ ROOT=`dirname $0`/..
rm -rf ${ROOT}/build
mkdir -p ${ROOT}/build
-cp -r ${ROOT}/../desktop-client/build ${ROOT}/build/client-build
+cp -r ${ROOT}/../desktop-client/build-electron ${ROOT}/build/client-build
# Remove the embedded backend for the browser version. Will improve
# this process
@@ -14,9 +14,8 @@ rm -rf ${ROOT}/build/client-build/*.wasm
rm -rf ${ROOT}/build/client-build/*.map
# Copy loot-core into build directory
-mkdir -p ${ROOT}/build/loot-core/lib-dist
-ls ${ROOT}/build/loot-core/lib-dist
-cp ${ROOT}/../loot-core/lib-dist/bundle.desktop.js ${ROOT}/build/loot-core/lib-dist/bundle.desktop.js
+mkdir -p ${ROOT}/build/loot-core/lib-dist/electron
+cp ${ROOT}/../loot-core/lib-dist/electron/bundle.desktop.js ${ROOT}/build/loot-core/lib-dist/electron/bundle.desktop.js
cp ${ROOT}/../loot-core/default-db.sqlite ${ROOT}/build/loot-core/default-db.sqlite
cp -r ${ROOT}/../loot-core/migrations ${ROOT}/build/loot-core/migrations
diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts
index 33085a2b22..3a9d4e8608 100644
--- a/packages/desktop-electron/index.ts
+++ b/packages/desktop-electron/index.ts
@@ -32,8 +32,8 @@ import './security';
const isDev = !app.isPackaged; // dev mode if not packaged
process.env.lootCoreScript = isDev
- ? 'loot-core/lib-dist/bundle.desktop.js' // serve from local output in development (provides hot-reloading)
- : path.resolve(__dirname, 'loot-core/lib-dist/bundle.desktop.js'); // serve from build in production
+ ? 'loot-core/lib-dist/electron/bundle.desktop.js' // serve from local output in development (provides hot-reloading)
+ : path.resolve(__dirname, 'loot-core/lib-dist/electron/bundle.desktop.js'); // serve from build in production
// This allows relative URLs to be resolved to app:// which makes
// local assets load correctly
diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json
index 4002e9220a..db7550e480 100644
--- a/packages/desktop-electron/package.json
+++ b/packages/desktop-electron/package.json
@@ -21,7 +21,7 @@
"!**/*.js.map",
"!**/stats.json",
"!build/client-build/sql-wasm.wasm",
- "!build/loot-core/lib-dist/{browser,bundle.mobile*}"
+ "!build/loot-core/lib-dist/electron/{browser,bundle.mobile*}"
],
"beforePack": "./build/beforePackHook.js",
"mac": {
diff --git a/packages/loot-core/src/platform/server/fs/index.electron.ts b/packages/loot-core/src/platform/server/fs/index.electron.ts
index a0508c9d44..587c8ff425 100644
--- a/packages/loot-core/src/platform/server/fs/index.electron.ts
+++ b/packages/loot-core/src/platform/server/fs/index.electron.ts
@@ -10,10 +10,15 @@ export { getDocumentDir, getBudgetDir, _setDocumentDir } from './shared';
let rootPath = path.join(__dirname, '..', '..', '..', '..');
-if (__filename.match('bundle')) {
- // The file name is not our filename and indicates that we're in the
- // bundled form. Because of this, the root path is different.
- rootPath = path.join(__dirname, '..');
+switch (path.basename(__filename)) {
+ case 'bundle.api.js': // api bundle uses the electron bundle - account for its file structure
+ rootPath = path.join(__dirname, '..');
+ break;
+ case 'bundle.desktop.js': // electron app
+ rootPath = path.join(__dirname, '..', '..');
+ break;
+ default:
+ break;
}
export const init = () => {
diff --git a/packages/loot-core/webpack/webpack.desktop.config.js b/packages/loot-core/webpack/webpack.desktop.config.js
index a6379dd5b8..2ce92a6f36 100644
--- a/packages/loot-core/webpack/webpack.desktop.config.js
+++ b/packages/loot-core/webpack/webpack.desktop.config.js
@@ -11,7 +11,7 @@ module.exports = {
target: 'node',
devtool: 'source-map',
output: {
- path: path.resolve(path.join(__dirname, '/../lib-dist')),
+ path: path.resolve(path.join(__dirname, '/../lib-dist/electron')),
filename: 'bundle.desktop.js',
sourceMapFilename: 'bundle.desktop.js.map',
libraryTarget: 'commonjs2',
diff --git a/upcoming-release-notes/3801.md b/upcoming-release-notes/3801.md
new file mode 100644
index 0000000000..f2c5878e5f
--- /dev/null
+++ b/upcoming-release-notes/3801.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MikesGlitch]
+---
+
+Update build folder structure to allow separation of web and electron builds