From fbcd3a50ca465aff622e19f1864ad19fa291689a Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Wed, 20 Aug 2025 06:40:48 +0000 Subject: [PATCH] feat: implement dynamic platform entry point system - Add src/main.ts as dynamic entry point that loads platform-specific code - Update index.html to use dynamic main.ts instead of hardcoded main.web.ts - Remove external capacitor config from vite.config.common.mts to ensure proper bundling - Enables consistent platform detection across all build targets - Use proper logger utility instead of console.log for platform detection logging --- index.html | 2 +- src/main.ts | 26 ++++++++++++++++++++++++++ vite.config.common.mts | 4 ---- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/main.ts diff --git a/index.html b/index.html index d2ce14a5..d276108b 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,6 @@
- + diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 00000000..a58becb7 --- /dev/null +++ b/src/main.ts @@ -0,0 +1,26 @@ +/** + * @file Dynamic Main Entry Point + * @author Matthew Raymer + * + * This file dynamically loads the appropriate platform-specific main entry point + * based on the current environment and build configuration. + */ + +import { logger } from "./utils/logger"; + +// Check the platform from environment variables +const platform = process.env.VITE_PLATFORM || "web"; + +logger.info(`[Main] 🚀 Loading TimeSafari for platform: ${platform}`); + +// Dynamically import the appropriate main entry point +if (platform === "capacitor") { + logger.info(`[Main] 📱 Loading Capacitor-specific entry point`); + import("./main.capacitor"); +} else if (platform === "electron") { + logger.info(`[Main] 💻 Loading Electron-specific entry point`); + import("./main.electron"); +} else { + logger.info(`[Main] 🌐 Loading Web-specific entry point`); + import("./main.web"); +} diff --git a/vite.config.common.mts b/vite.config.common.mts index 198f6ba3..848b3b9c 100644 --- a/vite.config.common.mts +++ b/vite.config.common.mts @@ -8,7 +8,6 @@ import { fileURLToPath } from 'url'; // Load environment variables dotenv.config({ path: `.env.${process.env.NODE_ENV}` }) - const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -36,9 +35,6 @@ export async function createBuildConfig(platform: string): Promise { assetsDir: 'assets', chunkSizeWarningLimit: 1000, rollupOptions: { - external: isNative - ? ['@capacitor/app'] - : [], output: { format: 'esm', generatedCode: {