import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { defineConfig, type Plugin } from 'vite'; import react from '@vitejs/plugin-react'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const repoRoot = path.resolve(__dirname, '..'); const qwbCore = path.resolve(repoRoot, 'src'); const qwbVisitor = path.resolve(repoRoot, 'packages/qwb-visitor/src'); const builderStoreShim = path.resolve(qwbVisitor, 'store/builderStoreShim.ts'); function qAppHtmlPost(): Plugin { return { name: 'qapp-html', transformIndexHtml: { order: 'post', handler(html) { let h = html.replace(/\s+crossorigin(?:=[^\s>]*)?/gi, ''); const re = /]*\btype="module"[^>]*\bsrc="[^"]+"[^>]*>\s*<\/script>\s*/i; const m = h.match(re); if (m) { const tag = m[0].trim(); h = h.replace(re, ''); h = h.replace('', ` ${tag}\n `); } return h; }, }, }; } export default defineConfig({ plugins: [react(), qAppHtmlPost()], base: './', resolve: { alias: { '@qwb/core': qwbCore, '@qwb/visitor': qwbVisitor, '@qwb/styles': path.resolve(repoRoot, 'style.css'), [path.resolve(qwbCore, 'store/builderStore.ts')]: builderStoreShim, [path.resolve(qwbCore, 'lib/qortalEnv.ts')]: path.resolve(__dirname, 'src/lib/qortalEnvShim.ts'), [path.resolve(qwbCore, 'lib/qortalClient.ts')]: path.resolve(__dirname, 'src/lib/qortalClientShim.ts'), }, dedupe: ['react', 'react-dom', 'zustand'], }, build: { outDir: 'dist', assetsDir: 'assets', sourcemap: false, }, optimizeDeps: { include: ['react', 'react-dom', 'zustand'], }, });