b54a3139c7
Includes QWB, Qortal Web, and Q-Shops Q-Apps with shared packages and build scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
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));
|
|
|
|
/**
|
|
* Vite 6 can add `crossorigin` to the module script and CSS. In Qortal Hub, that uses a
|
|
* CORS-style fetch; some hosts do not return ACAO, so the JS never executes and the UI stays on
|
|
* the static "Loading" placeholder. Strip it for typical same-origin Q-App trees.
|
|
* Move the app entry to the end of <body> (after ./zip-store.js) so the IIFE is defined first.
|
|
*/
|
|
function qAppHtmlPost(): Plugin {
|
|
return {
|
|
name: 'qapp-html',
|
|
transformIndexHtml: {
|
|
order: 'post',
|
|
handler(html) {
|
|
let h = html.replace(/\s+crossorigin(?:=[^\s>]*)?/gi, '');
|
|
const re = /<script[^>]*\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('</body>', ` ${tag}\n </body>`);
|
|
}
|
|
return h;
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
// Q-Apps and static sites are often served from a folder — relative asset URLs.
|
|
export default defineConfig({
|
|
plugins: [react(), qAppHtmlPost()],
|
|
base: './',
|
|
build: {
|
|
// dev.html = Vite/React source. Input key "index" → dist/index.html (for manifest + index.hub copy).
|
|
rollupOptions: {
|
|
input: {
|
|
index: path.resolve(__dirname, 'dev.html'),
|
|
/** Public site only (Visual Editor content) for export + preview. */
|
|
site: path.resolve(__dirname, 'site.html'),
|
|
},
|
|
},
|
|
outDir: 'dist',
|
|
assetsDir: 'assets',
|
|
sourcemap: false,
|
|
},
|
|
}); |