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 { defineConfig } from "vite"; |
||||
import { createBuildConfig } from "./vite.config.common.mts"; |
|
||||
import path from 'path'; |
import path from 'path'; |
||||
|
|
||||
export default defineConfig(async ({ mode }) => { |
export default defineConfig({ |
||||
const baseConfig = await createBuildConfig('electron'); |
build: { |
||||
const isWebBuild = mode === 'electron'; |
outDir: 'dist-electron', |
||||
|
rollupOptions: { |
||||
return mergeConfig(baseConfig, { |
input: { |
||||
build: { |
main: path.resolve(__dirname, 'src/electron/main.ts'), |
||||
outDir: isWebBuild ? 'dist' : 'dist-electron', |
preload: path.resolve(__dirname, 'src/electron/preload.js'), |
||||
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]', |
|
||||
}, |
|
||||
}, |
}, |
||||
target: isWebBuild ? 'esnext' : 'node18', |
external: [ |
||||
minify: !isWebBuild, |
// Node.js built-ins |
||||
sourcemap: true, |
'stream', |
||||
}, |
'path', |
||||
resolve: { |
'fs', |
||||
alias: { |
'crypto', |
||||
'@': path.resolve(__dirname, 'src'), |
'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: { |
target: 'node18', |
||||
include: ['@/utils/logger'] |
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: [ |
}, |
||||
{ |
optimizeDeps: { |
||||
name: 'typescript-transform', |
exclude: [ |
||||
transform(code: string, id: string) { |
'stream', |
||||
if (id.endsWith('main.ts')) { |
'path', |
||||
// Replace the logger import with inline logger |
'fs', |
||||
return code.replace( |
'crypto', |
||||
/import\s*{\s*logger\s*}\s*from\s*['"]@\/utils\/logger['"];?/, |
'buffer', |
||||
`const logger = { |
'util', |
||||
log: (...args) => console.log(...args), |
'events', |
||||
error: (...args) => console.error(...args), |
'url', |
||||
info: (...args) => console.info(...args), |
'assert', |
||||
warn: (...args) => console.warn(...args), |
'os', |
||||
debug: (...args) => console.debug(...args), |
'net', |
||||
};` |
'http', |
||||
); |
'https', |
||||
} |
'zlib', |
||||
return code; |
'child_process', |
||||
} |
'axios', |
||||
}, |
'axios/dist/axios', |
||||
{ |
'axios/dist/node/axios.cjs' |
||||
name: 'remove-sw-imports', |
] |
||||
transform(code: string, id: string) { |
}, |
||||
// Remove service worker imports and registrations |
plugins: [ |
||||
if (id.includes('registerServiceWorker') || |
{ |
||||
id.includes('register-service-worker') || |
name: 'typescript-transform', |
||||
id.includes('sw_scripts') || |
transform(code: string, id: string) { |
||||
id.includes('PushNotificationPermission') || |
if (id.endsWith('main.ts')) { |
||||
code.includes('navigator.serviceWorker')) { |
return code.replace( |
||||
return { |
/import\s*{\s*logger\s*}\s*from\s*['"]@\/utils\/logger['"];?/, |
||||
code: code |
`const logger = { |
||||
.replace(/import.*registerServiceWorker.*$/mg, '') |
log: (...args) => console.log(...args), |
||||
.replace(/import.*register-service-worker.*$/mg, '') |
error: (...args) => console.error(...args), |
||||
.replace(/navigator\.serviceWorker/g, 'undefined') |
info: (...args) => console.info(...args), |
||||
.replace(/if\s*\([^)]*serviceWorker[^)]*\)\s*{[^}]*}/g, '') |
warn: (...args) => console.warn(...args), |
||||
.replace(/import.*workbox.*$/mg, '') |
debug: (...args) => console.debug(...args), |
||||
.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; |
|
||||
} |
} |
||||
|
return code; |
||||
} |
} |
||||
], |
} |
||||
ssr: { |
], |
||||
noExternal: ['@/utils/logger'] |
base: './', |
||||
}, |
publicDir: 'public', |
||||
base: './', |
|
||||
publicDir: 'public', |
|
||||
}); |
|
||||
}); |
}); |
Loading…
Reference in new issue