Browse Source
- Changed from direct plugin usage to SQLiteConnection pattern - Matches how platform services use the SQLite plugin - Removed handle() method dependency - Added proper method routing in IPC handler The app now launches without initialization errors. Next steps: - Test actual SQLite operations (createConnection, query, etc.) - Verify database creation and access - Add error handling for database operationspull/134/head
7 changed files with 221 additions and 129 deletions
@ -1,120 +1,102 @@ |
|||
import { defineConfig, mergeConfig } from "vite"; |
|||
import { createBuildConfig } from "./vite.config.common.mts"; |
|||
import { defineConfig } from "vite"; |
|||
import path from 'path'; |
|||
|
|||
export default defineConfig(async ({ mode }) => { |
|||
const baseConfig = await createBuildConfig('electron'); |
|||
const isWebBuild = mode === 'electron'; |
|||
|
|||
return mergeConfig(baseConfig, { |
|||
build: { |
|||
outDir: isWebBuild ? 'dist' : 'dist-electron', |
|||
rollupOptions: isWebBuild ? { |
|||
// Web app build configuration |
|||
input: path.resolve(__dirname, 'index.html'), |
|||
output: { |
|||
format: 'esm', |
|||
entryFileNames: 'assets/[name]-[hash].js', |
|||
chunkFileNames: 'assets/[name]-[hash].js', |
|||
assetFileNames: 'assets/[name]-[hash].[ext]' |
|||
} |
|||
} : { |
|||
// Main process build configuration |
|||
input: { |
|||
main: path.resolve(__dirname, 'src/electron/main.ts'), |
|||
preload: path.resolve(__dirname, 'src/electron/preload.js'), |
|||
}, |
|||
external: [ |
|||
'electron', |
|||
'@capacitor-community/sqlite', |
|||
'@capacitor-community/sqlite/electron', |
|||
'better-sqlite3-multiple-ciphers' |
|||
], |
|||
output: { |
|||
format: 'cjs', |
|||
entryFileNames: '[name].js', |
|||
assetFileNames: 'assets/[name].[ext]', |
|||
}, |
|||
export default defineConfig({ |
|||
build: { |
|||
outDir: 'dist-electron', |
|||
rollupOptions: { |
|||
input: { |
|||
main: path.resolve(__dirname, 'src/electron/main.ts'), |
|||
preload: path.resolve(__dirname, 'src/electron/preload.js'), |
|||
}, |
|||
target: isWebBuild ? 'esnext' : 'node18', |
|||
minify: !isWebBuild, |
|||
sourcemap: true, |
|||
}, |
|||
resolve: { |
|||
alias: { |
|||
'@': path.resolve(__dirname, 'src'), |
|||
external: [ |
|||
// Node.js built-ins |
|||
'stream', |
|||
'path', |
|||
'fs', |
|||
'crypto', |
|||
'buffer', |
|||
'util', |
|||
'events', |
|||
'url', |
|||
'assert', |
|||
'os', |
|||
'net', |
|||
'http', |
|||
'https', |
|||
'zlib', |
|||
'child_process', |
|||
// Electron and Capacitor |
|||
'electron', |
|||
'@capacitor/core', |
|||
'@capacitor-community/sqlite', |
|||
'@capacitor-community/sqlite/electron', |
|||
'@capacitor-community/sqlite/electron/dist/plugin', |
|||
'better-sqlite3-multiple-ciphers', |
|||
// HTTP clients |
|||
'axios', |
|||
'axios/dist/axios', |
|||
'axios/dist/node/axios.cjs' |
|||
], |
|||
output: { |
|||
format: 'cjs', |
|||
entryFileNames: '[name].js', |
|||
assetFileNames: 'assets/[name].[ext]', |
|||
}, |
|||
}, |
|||
optimizeDeps: { |
|||
include: ['@/utils/logger'] |
|||
target: 'node18', |
|||
minify: false, |
|||
sourcemap: true, |
|||
}, |
|||
resolve: { |
|||
alias: { |
|||
'@': path.resolve(__dirname, 'src'), |
|||
// Use Node.js version of axios in electron |
|||
'axios': 'axios/dist/node/axios.cjs' |
|||
}, |
|||
plugins: [ |
|||
{ |
|||
name: 'typescript-transform', |
|||
transform(code: string, id: string) { |
|||
if (id.endsWith('main.ts')) { |
|||
// Replace the logger import with inline logger |
|||
return code.replace( |
|||
/import\s*{\s*logger\s*}\s*from\s*['"]@\/utils\/logger['"];?/, |
|||
`const logger = { |
|||
log: (...args) => console.log(...args), |
|||
error: (...args) => console.error(...args), |
|||
info: (...args) => console.info(...args), |
|||
warn: (...args) => console.warn(...args), |
|||
debug: (...args) => console.debug(...args), |
|||
};` |
|||
); |
|||
} |
|||
return code; |
|||
} |
|||
}, |
|||
{ |
|||
name: 'remove-sw-imports', |
|||
transform(code: string, id: string) { |
|||
// Remove service worker imports and registrations |
|||
if (id.includes('registerServiceWorker') || |
|||
id.includes('register-service-worker') || |
|||
id.includes('sw_scripts') || |
|||
id.includes('PushNotificationPermission') || |
|||
code.includes('navigator.serviceWorker')) { |
|||
return { |
|||
code: code |
|||
.replace(/import.*registerServiceWorker.*$/mg, '') |
|||
.replace(/import.*register-service-worker.*$/mg, '') |
|||
.replace(/navigator\.serviceWorker/g, 'undefined') |
|||
.replace(/if\s*\([^)]*serviceWorker[^)]*\)\s*{[^}]*}/g, '') |
|||
.replace(/import.*workbox.*$/mg, '') |
|||
.replace(/importScripts\([^)]*\)/g, '') |
|||
}; |
|||
} |
|||
return code; |
|||
} |
|||
}, |
|||
{ |
|||
name: 'remove-sw-files', |
|||
enforce: 'pre', |
|||
resolveId(id: string) { |
|||
// Prevent service worker files from being included |
|||
if (id.includes('sw.js') || |
|||
id.includes('workbox') || |
|||
id.includes('registerSW.js') || |
|||
id.includes('manifest.webmanifest')) { |
|||
return '\0empty'; |
|||
} |
|||
return null; |
|||
}, |
|||
load(id: string) { |
|||
if (id === '\0empty') { |
|||
return 'export default {}'; |
|||
} |
|||
return null; |
|||
}, |
|||
optimizeDeps: { |
|||
exclude: [ |
|||
'stream', |
|||
'path', |
|||
'fs', |
|||
'crypto', |
|||
'buffer', |
|||
'util', |
|||
'events', |
|||
'url', |
|||
'assert', |
|||
'os', |
|||
'net', |
|||
'http', |
|||
'https', |
|||
'zlib', |
|||
'child_process', |
|||
'axios', |
|||
'axios/dist/axios', |
|||
'axios/dist/node/axios.cjs' |
|||
] |
|||
}, |
|||
plugins: [ |
|||
{ |
|||
name: 'typescript-transform', |
|||
transform(code: string, id: string) { |
|||
if (id.endsWith('main.ts')) { |
|||
return code.replace( |
|||
/import\s*{\s*logger\s*}\s*from\s*['"]@\/utils\/logger['"];?/, |
|||
`const logger = { |
|||
log: (...args) => console.log(...args), |
|||
error: (...args) => console.error(...args), |
|||
info: (...args) => console.info(...args), |
|||
warn: (...args) => console.warn(...args), |
|||
debug: (...args) => console.debug(...args), |
|||
};` |
|||
); |
|||
} |
|||
return code; |
|||
} |
|||
], |
|||
ssr: { |
|||
noExternal: ['@/utils/logger'] |
|||
}, |
|||
base: './', |
|||
publicDir: 'public', |
|||
}); |
|||
} |
|||
], |
|||
base: './', |
|||
publicDir: 'public', |
|||
}); |
Loading…
Reference in new issue