Skip to content

A local-first personal finance app

[AI] Leave source maps out of the Capacitor mobile apps (#9329)

Matiss Janis Aboltins1f868b890fb6
diff --git a/packages/mobile-client/.gitignore b/packages/mobile-client/.gitignore
new file mode 100644
index 0000000000..f8d728c119
--- /dev/null
+++ b/packages/mobile-client/.gitignore
@@ -0,0 +1 @@
+www
diff --git a/packages/mobile-client/bin/stage-www.mjs b/packages/mobile-client/bin/stage-www.mjs
new file mode 100644
index 0000000000..3966a26380
--- /dev/null
+++ b/packages/mobile-client/bin/stage-www.mjs
@@ -0,0 +1,25 @@
+// Stages the web build into `www/` for Capacitor to copy into the native
+// apps. Source maps are left out: nothing on a phone reads them and they
+// are around 70% of the web build, so shipping them more than triples the
+// installed app size.
+import { cpSync, rmSync } from 'node:fs';
+import { createRequire } from 'node:module';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const require = createRequire(import.meta.url);
+const webBuildDir = path.join(
+ path.dirname(require.resolve('@actual-app/web/package.json')),
+ 'build',
+);
+const wwwDir = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ '..',
+ 'www',
+);
+
+rmSync(wwwDir, { recursive: true, force: true });
+cpSync(webBuildDir, wwwDir, {
+ recursive: true,
+ filter: src => !src.endsWith('.map'),
+});
diff --git a/packages/mobile-client/capacitor.config.ts b/packages/mobile-client/capacitor.config.ts
index e8a376309a..bcfcb102e8 100644
--- a/packages/mobile-client/capacitor.config.ts
+++ b/packages/mobile-client/capacitor.config.ts
@@ -1,16 +1,11 @@
-import path from 'node:path';
-
import type { CapacitorConfig } from '@capacitor/cli';
-const actualAppWebBuildPath = path.join(
- path.dirname(require.resolve('@actual-app/web/package.json')),
- 'build',
-);
-
const baseConfig: CapacitorConfig = {
appId: 'org.actualbudget',
appName: 'Actual Budget',
- webDir: actualAppWebBuildPath,
+ // Staged from the web build by `bin/stage-www.mjs` (run by the sync
+ // scripts), which leaves out files the native apps do not need.
+ webDir: 'www',
};
const devConfig: CapacitorConfig = {
diff --git a/packages/mobile-client/package.json b/packages/mobile-client/package.json
index 38364f07aa..a022466a05 100644
--- a/packages/mobile-client/package.json
+++ b/packages/mobile-client/package.json
@@ -6,8 +6,9 @@
"build"
],
"scripts": {
- "sync:ios": "cap sync ios",
- "sync:android": "cap sync android",
+ "stage:www": "node bin/stage-www.mjs",
+ "sync:ios": "yarn stage:www && cap sync ios",
+ "sync:android": "yarn stage:www && cap sync android",
"build:ios": "yarn sync:ios && xcodebuild -workspace ios/App/App.xcworkspace -scheme App -archivePath ./build/App.xcarchive archive CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO",
"build:android": "yarn sync:android && cd android/ && ./gradlew assembleDebug && cp ./app/build/outputs/apk/debug/app-debug.apk ../build/",
"release:ios": "NODE_ENV=production yarn sync:ios && xcodebuild -workspace ios/App/App.xcworkspace -scheme App -configuration Release -destination generic/platform=iOS -archivePath build/App.xcarchive -allowProvisioningUpdates ${XCODEBUILD_AUTH_ARGS:-} DEVELOPMENT_TEAM=\"$APPLE_TEAM_ID\" MARKETING_VERSION=\"$npm_package_version\" CURRENT_PROJECT_VERSION=\"$(date -u +%Y%m%d%H%M)\" archive && xcodebuild -exportArchive -archivePath build/App.xcarchive -exportOptionsPlist ios/App/ExportOptions.plist -exportPath build/export -allowProvisioningUpdates ${XCODEBUILD_AUTH_ARGS:-}",
diff --git a/upcoming-release-notes/strip-mobile-source-maps.md b/upcoming-release-notes/strip-mobile-source-maps.md
new file mode 100644
index 0000000000..32ff19d3be
--- /dev/null
+++ b/upcoming-release-notes/strip-mobile-source-maps.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [MatissJanis]
+---
+
+Make the iOS and Android apps much smaller to download and install.