File size: 1,888 Bytes
ec8acdf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import { defineConfig } from 'vite';
const STATIC_SCRIPT_NONCE = 'wm-static-bootstrap';
function isWelcomeHtml(hostId: string) {
return hostId === 'welcome.html' || hostId.endsWith('/welcome.html');
}
function isWelcomeHydrationPreload(dep: string) {
const basename = dep.split('/').pop() ?? dep;
return basename.startsWith('index-') && basename.endsWith('.js');
}
export default defineConfig({
plugins: [react(), tailwindcss()],
base: '/pro/',
html: {
cspNonce: STATIC_SCRIPT_NONCE,
},
build: {
modulePreload: {
resolveDependencies: (filename, deps, context) => {
if (context.hostType !== 'html') return deps;
const hostId = 'hostId' in context && typeof context.hostId === 'string'
? context.hostId
: filename;
if (!isWelcomeHtml(hostId)) return deps;
return deps.filter(dep => !isWelcomeHydrationPreload(dep));
},
},
outDir: path.resolve(__dirname, '../public/pro'),
emptyOutDir: true,
rollupOptions: {
input: {
index: path.resolve(__dirname, 'index.html'),
welcome: path.resolve(__dirname, 'welcome.html'),
},
output: {
// Split the Sentry SDK into its own stable chunk. It's a critical-path
// dependency (initSentry() runs before render to catch early errors, so
// it isn't deferrable), but pulling it out of the catch-all vendor chunk
// keeps it cacheable across the frequent app-code redeploys that would
// otherwise re-bust its bytes.
manualChunks: (id) => {
if (id.includes('/node_modules/@sentry/')) return 'sentry';
return undefined;
},
},
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, '.'),
},
},
});
|