forked from trent_larson/crowd-funder-for-time-pwa
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
This commit is contained in:
@@ -11,6 +11,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module" src="/src/main.web.ts"></script>
|
<script type="module" src="/src/main.ts"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
26
src/main.ts
Normal file
26
src/main.ts
Normal file
@@ -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");
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@ import { fileURLToPath } from 'url';
|
|||||||
// Load environment variables
|
// Load environment variables
|
||||||
dotenv.config({ path: `.env.${process.env.NODE_ENV}` })
|
dotenv.config({ path: `.env.${process.env.NODE_ENV}` })
|
||||||
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
@@ -36,9 +35,6 @@ export async function createBuildConfig(platform: string): Promise<UserConfig> {
|
|||||||
assetsDir: 'assets',
|
assetsDir: 'assets',
|
||||||
chunkSizeWarningLimit: 1000,
|
chunkSizeWarningLimit: 1000,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: isNative
|
|
||||||
? ['@capacitor/app']
|
|
||||||
: [],
|
|
||||||
output: {
|
output: {
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
generatedCode: {
|
generatedCode: {
|
||||||
|
|||||||
Reference in New Issue
Block a user