98 lines
3.4 KiB
TypeScript
98 lines
3.4 KiB
TypeScript
import { createPublicKey } from 'crypto'
|
|
import { copyFileSync, mkdirSync, readdirSync, readFileSync } from 'fs'
|
|
import { resolve } from 'path'
|
|
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
const sharedAlias = [
|
|
{ find: /^@d3ro\/i18n\/main$/, replacement: resolve(__dirname, '../../packages/i18n/src/main.ts') },
|
|
{ find: /^@d3ro\/i18n$/, replacement: resolve(__dirname, '../../packages/i18n/src/index.tsx') },
|
|
{ find: /^@d3ro\/core(\/.*)?$/, replacement: `${resolve(__dirname, '../../packages/core/src')}$1` },
|
|
{ find: /^@d3ro\/ui(\/.*)?$/, replacement: `${resolve(__dirname, '../../packages/ui/src')}$1` },
|
|
]
|
|
|
|
const copyMainLocalesPlugin = {
|
|
name: 'copy-main-locales',
|
|
writeBundle(options: { dir?: string }): void {
|
|
const outDir = options.dir ?? resolve(__dirname, 'out/main')
|
|
const srcDir = resolve(__dirname, '../../packages/i18n/src/locales')
|
|
const destDir = resolve(outDir, 'locales')
|
|
mkdirSync(destDir, { recursive: true })
|
|
for (const file of readdirSync(srcDir)) {
|
|
if (file.endsWith('.json')) {
|
|
copyFileSync(resolve(srcDir, file), resolve(destDir, file))
|
|
}
|
|
}
|
|
},
|
|
}
|
|
|
|
const workspaceExclude = ['@d3ro/core', '@d3ro/ui', '@d3ro/i18n']
|
|
const licensePublicKeyPath = resolve(__dirname, 'resources/license/production-public.pem')
|
|
const licensePublicKey = readFileSync(licensePublicKeyPath, 'utf8').trim()
|
|
const parsedLicensePublicKey = createPublicKey(licensePublicKey)
|
|
if (parsedLicensePublicKey.asymmetricKeyType !== 'ed25519') {
|
|
throw new Error(`Desktop license public key must be Ed25519: ${licensePublicKeyPath}`)
|
|
}
|
|
|
|
export default defineConfig({
|
|
main: {
|
|
// 공개키만 main bundle에 주입한다. 대응 ADMIN_LICENSE_PRIVATE_KEY는 admin 서버 전용이다.
|
|
define: {
|
|
'process.env.D3RO_LICENSE_PUBLIC_KEY': JSON.stringify(licensePublicKey)
|
|
},
|
|
plugins: [
|
|
externalizeDepsPlugin({
|
|
exclude: ['electron-store', ...workspaceExclude]
|
|
}),
|
|
copyMainLocalesPlugin
|
|
],
|
|
resolve: { alias: sharedAlias }
|
|
},
|
|
preload: {
|
|
plugins: [externalizeDepsPlugin({ exclude: workspaceExclude })],
|
|
build: {
|
|
rollupOptions: {
|
|
input: {
|
|
index: resolve(__dirname, 'src/preload/index.ts'),
|
|
popup: resolve(__dirname, 'src/preload/popup.ts')
|
|
}
|
|
}
|
|
},
|
|
resolve: { alias: sharedAlias }
|
|
},
|
|
renderer: {
|
|
build: {
|
|
rollupOptions: {
|
|
input: {
|
|
index: resolve(__dirname, 'src/renderer/index.html'),
|
|
'popups/recording-tip': resolve(
|
|
__dirname,
|
|
'src/renderer/popups/recording-tip/index.html'
|
|
),
|
|
'popups/result-popup': resolve(
|
|
__dirname,
|
|
'src/renderer/popups/result-popup/index.html'
|
|
),
|
|
'popups/history-popup': resolve(
|
|
__dirname,
|
|
'src/renderer/popups/history-popup/index.html'
|
|
),
|
|
'popups/command-popup': resolve(
|
|
__dirname,
|
|
'src/renderer/popups/command-popup/index.html'
|
|
),
|
|
'popups/caption-overlay': resolve(
|
|
__dirname,
|
|
'src/renderer/popups/caption-overlay/index.html'
|
|
),
|
|
'popups/suggestion-overlay': resolve(
|
|
__dirname,
|
|
'src/renderer/popups/suggestion-overlay/index.html'
|
|
)
|
|
}
|
|
}
|
|
},
|
|
resolve: { alias: sharedAlias },
|
|
plugins: [react()]
|
|
}
|
|
})
|