App source (main/preload/worker/renderer) -> ESM; app is now type: module; __dirname via import.meta.url; worker spawned with type module. Preload is built as CJS (electron-vite output format) because the sandboxed renderer does not support ESM preload; main loads ../preload/index.js. Removed dead imports (nativeImage, readline) and the obsolete scripts/dev.js. Tests: 4 app tests require->import; app-main-settings rewritten with node:test mock.module + dynamic import (replacing CJS Module._load mocking); test script adds --experimental-test-module-mocks. electron-vite build clean, 119/119, and npm run dev verified: app launches, preload bridges IPC, data loads.
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { resolve } from 'node:path';
|
|
import { defineConfig, externalizeDepsPlugin } from 'electron-vite';
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
// Kept CommonJS for the first electron-vite boot (no "type":"module" yet); the
|
|
// TS + ESM migration is a later stage. Each main-process module is its own input
|
|
// so it is emitted to out/main/<name>.js and the CommonJS require("./x") calls
|
|
// between them (and `new Worker(__dirname/indexer-worker.js)`) resolve at runtime.
|
|
export default defineConfig({
|
|
main: {
|
|
plugins: [externalizeDepsPlugin()],
|
|
build: {
|
|
rollupOptions: {
|
|
input: {
|
|
index: resolve('src/main/index.js'),
|
|
indexer: resolve('src/main/indexer.js'),
|
|
'indexer-service': resolve('src/main/indexer-service.js'),
|
|
'indexer-worker': resolve('src/main/indexer-worker.js'),
|
|
'indexer-worker-client': resolve('src/main/indexer-worker-client.js'),
|
|
'recap-capture-query': resolve('src/main/recap-capture-query.js'),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
preload: {
|
|
plugins: [externalizeDepsPlugin()],
|
|
build: {
|
|
rollupOptions: {
|
|
// Electron sandbox does not support ESM preload — emit CJS index.js
|
|
// (main loads ../preload/index.js) even though the project is ESM.
|
|
output: { format: 'cjs', entryFileNames: '[name].js' },
|
|
},
|
|
},
|
|
},
|
|
renderer: {
|
|
plugins: [vue()],
|
|
},
|
|
});
|