2024-08-21 11:05:07 +03:00
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
|
2024-11-16 16:00:12 +03:00
|
|
|
/** @type {import('@fuman/build/vite').CustomBuildConfig} */
|
2024-08-21 11:05:07 +03:00
|
|
|
export default () => {
|
|
|
|
const clientId = fileURLToPath(new URL('./src/client.ts', import.meta.url))
|
|
|
|
|
|
|
|
return {
|
2024-11-16 16:00:12 +03:00
|
|
|
viteConfig: {
|
|
|
|
build: {
|
|
|
|
rollupOptions: {
|
|
|
|
external: ['@mtcute/crypto-node'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pluginsPre: [
|
2024-08-21 11:05:07 +03:00
|
|
|
{
|
|
|
|
// very much a crutch, but it works
|
|
|
|
// i couldn't figure out a way to hook into the esm->cjs transform,
|
|
|
|
// so i'm just replacing the await import with require and then back
|
|
|
|
name: 'mtcute-node-build-plugin',
|
|
|
|
transform(code, id) {
|
|
|
|
if (id === clientId) {
|
|
|
|
return code.replace('await import(', 'require(')
|
|
|
|
}
|
|
|
|
|
|
|
|
return code
|
|
|
|
},
|
|
|
|
generateBundle(output, bundle) {
|
|
|
|
if (output.format !== 'es') return
|
|
|
|
|
|
|
|
let found = false
|
|
|
|
|
|
|
|
for (const chunk of Object.values(bundle)) {
|
|
|
|
if (chunk.code.match(/require\("@mtcute\/crypto-node"\)/)) {
|
|
|
|
found = true
|
2024-08-27 23:05:20 +03:00
|
|
|
chunk.code = chunk.code.replace('require("@mtcute/crypto-node")', '(await import("@mtcute/crypto-node"))')
|
2024-08-21 11:05:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
throw new Error('Could not find crypto-node import')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2024-12-28 11:17:11 +03:00
|
|
|
typedoc: {
|
|
|
|
externalPattern: [
|
|
|
|
'../core/**',
|
|
|
|
'../html-parser/**',
|
|
|
|
'../markdown-parser/**',
|
|
|
|
'../sqlite/**',
|
|
|
|
],
|
|
|
|
},
|
2024-08-21 11:05:07 +03:00
|
|
|
}
|
|
|
|
}
|