feat: add deploy script that builds directly to ../public_html

This commit is contained in:
2026-03-14 21:55:04 +03:00
parent 534bdd3bb5
commit aa6a972ce6
3 changed files with 8 additions and 6 deletions

View File

@@ -6,6 +6,7 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build && vite build --ssr src/entry-server.jsx --outDir dist/server && node scripts/prerender.mjs", "build": "vite build && vite build --ssr src/entry-server.jsx --outDir dist/server && node scripts/prerender.mjs",
"deploy": "BUILD_DIR=../public_html vite build && BUILD_DIR=../public_html vite build --ssr src/entry-server.jsx --outDir ../public_html/server && BUILD_DIR=../public_html node scripts/prerender.mjs",
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {

View File

@@ -4,18 +4,19 @@ import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url)) const __dirname = dirname(fileURLToPath(import.meta.url))
const root = resolve(__dirname, '..') const root = resolve(__dirname, '..')
const buildDir = process.env.BUILD_DIR || 'dist'
// Import SSR bundle built by vite build --ssr // Import SSR bundle built by vite build --ssr
const { render } = await import('../dist/server/entry-server.js') const { render } = await import(`../${buildDir}/server/entry-server.js`)
let html = readFileSync(resolve(root, 'dist/index.html'), 'utf-8') let html = readFileSync(resolve(root, buildDir, 'index.html'), 'utf-8')
// Inject prerendered HTML // Inject prerendered HTML
const appHtml = render() const appHtml = render()
html = html.replace('<div id="root"></div>', `<div id="root">${appHtml}</div>`) html = html.replace('<div id="root"></div>', `<div id="root">${appHtml}</div>`)
// Fix preload font: find actual cyrillic-700 woff2 hash in dist/assets // Fix preload font: find actual cyrillic-700 woff2 hash in dist/assets
const assetsDir = resolve(root, 'dist/assets') const assetsDir = resolve(root, buildDir, 'assets')
const fontFile = readdirSync(assetsDir).find(f => f.match(/manrope-cyrillic-700-normal-.+\.woff2/)) const fontFile = readdirSync(assetsDir).find(f => f.match(/manrope-cyrillic-700-normal-.+\.woff2/))
if (fontFile) { if (fontFile) {
html = html.replace( html = html.replace(
@@ -25,9 +26,9 @@ if (fontFile) {
console.log(`✓ Preload font updated: ${fontFile}`) console.log(`✓ Preload font updated: ${fontFile}`)
} }
writeFileSync(resolve(root, 'dist/index.html'), html) writeFileSync(resolve(root, buildDir, 'index.html'), html)
// Cleanup SSR bundle // Cleanup SSR bundle
rmSync(resolve(root, 'dist/server'), { recursive: true, force: true }) rmSync(resolve(root, buildDir, 'server'), { recursive: true, force: true })
console.log('✓ Prerendered index.html') console.log('✓ Prerendered index.html')

View File

@@ -4,6 +4,6 @@ import react from '@vitejs/plugin-react'
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
build: { build: {
outDir: 'dist', outDir: process.env.BUILD_DIR || 'dist',
}, },
}) })