İçeriğe geç

SSR Ayarlar

Bu sayfa @lentystyle/ssr içindeki iki ayrı config katmanını açıklar:

  • request-time render için LentySsrConfig
  • luis.config.mjs içindeki project-level ssr bloğu

Terminal window
pnpm add @lentystyle/ssr

LentySsrConfig, renderLentySsrSnapshot(), createLentySsrIntegration() ve diğer request-time SSR yüzeylerine geçen public config tipidir.

Bu katman:

  • runtime option default'larını tanımlar
  • HTML injection metadata'sını taşır
  • mode, adapter ve rewritePolicy gibi alanları resolved biçimde tutar

interface LentySsrConfig {
mode?: 'static' | 'ssr'
adapter?: 'none' | 'vue' | 'svelte' | 'react' | 'astro'
performance?: boolean
debug?: boolean
map?: boolean
lazy?: boolean
worker?: 'auto' | 'main' | 'worker'
assetBaseUrl?: string
globalCssHref?: string
bootstrapScriptSrc?: string
runtimeOptions?: string | Partial<LentySsrRuntimeOptions>
rewritePolicy?: 'auto' | 'prefer-static' | 'prefer-runtime'
}
FieldDefault
mode'ssr'
adapter'none'
debugfalse
performancefalse
mapfalse
lazyfalse
worker'auto'
assetBaseUrl/_hybrid
globalCssHrefnull
bootstrapScriptSrcnull
rewritePolicy'auto'
output.payloadMode'inline-json'
import { createLentySsrIntegration } from '@lentystyle/ssr'
const ssr = createLentySsrIntegration({
mode: 'ssr',
globalCssHref: '/assets/site.css',
bootstrapScriptSrc: '/assets/browser-entry.js',
runtimeOptions: 'performance,!worker',
})

Bu örnekte:

  • ortak global CSS her render'da <link rel="stylesheet"> olarak enjekte edilir
  • bootstrap script her render'da enjekte edilir
  • runtime options çözümlemesi performance: true ve worker: 'main' verir

SSR request helper'ları kendi dahili guard policy'si ile gelir; config üzerinden guardPolicy geçmezsiniz.

SurfaceGuard behavior
renderLentySsrSnapshot()preset: 'strict', htmlMode: 'ssr'
createLentySsrIntegration().renderRequest()preset: 'strict', htmlMode: 'ssr'
createLentySsrFrameworkAdapter().render()preset: 'strict', htmlMode: 'ssr'

Kısa örnek:

import { renderLentySsrSnapshot } from '@lentystyle/ssr'
await renderLentySsrSnapshot({}, {
routeId: '/docs/',
html: '<html><head></head><body><div class="card"></div></body></html>',
sources: [
{
sourceId: 'docs.luis',
source: '.card { color: #0f172a; }',
},
],
})

Ek guard config vermeseniz bile bu çağrı request envelope'u validate eder ve downstream hybrid compile adımında strict doğrulamayı korur.


SSR içindeki runtime option merge sırası sabittir:

package defaults
-> config.debug / performance / map / lazy / worker
-> config.runtimeOptions
-> source.runtimeOptions
  1. Temel default'lar uygulanır

    {
    debug: false,
    performance: false,
    map: false,
    lazy: false,
    worker: 'auto',
    }
  2. Top-level config flag'leri uygulanır

    debug, performance, map, lazy ve worker bu aşamada uygulanır.

  3. config.runtimeOptions patch'i uygulanır

    String veya object patch, top-level flag'leri override eder.

  4. Source-level override uygulanır

    input.sources[].runtimeOptions, config-level sonucu source bazında override eder.

runtimeOptions: 'debug,performance,!worker'

Sonuç:

{
debug: true,
performance: true,
map: false,
lazy: false,
worker: 'main',
}

Desteklenen token'lar:

  • debug, performance, map, lazy
  • !debug, !performance, !map, !lazy
  • worker -> worker: 'worker'
  • !worker -> worker: 'main'
const result = await renderLentySsrSnapshot(
{ runtimeOptions: 'debug,worker' },
{
routeId: '/docs/',
html,
sources: [
{
sourceId: 'docs.luis',
source,
runtimeOptions: '!debug,lazy,!worker',
},
],
},
)

Bu source için final runtime options:

{
debug: false,
performance: false,
map: false,
lazy: true,
worker: 'main',
}

Request-level default ve source-level override birlikte

Section titled “Request-level default ve source-level override birlikte”

Config:

const config = {
runtimeOptions: 'debug,performance,worker',
}

Source:

const input = {
routeId: '/docs/',
html: '<html><head></head><body><div class="card"></div></body></html>',
sources: [
{
sourceId: 'docs.luis',
source: '.card { color: #0f172a; }',
runtimeOptions: '!debug,lazy,!worker',
},
],
}

Bu source için final runtime options:

{
debug: false,
performance: true,
map: false,
lazy: true,
worker: 'main',
}

Project-level SSR config tipi LuisSsrProjectConfig'dir. LentySsrConfig alanlarını devralır ve preview veya project-level alanlar ekler.

import { defineLuisConfig } from '@lentystyle/core'
export default defineLuisConfig({
ssr: {
mode: 'ssr',
outDirName: 'dist-ssr',
maxEntries: 100,
defaultRuntimeOptions: '',
include: ['docs/**', '**/*.html'],
exclude: ['admin/**'],
},
})
FieldPurposeDefault
outDirNamePreview HTML kök dizininin adı'dist-ssr'
maxEntriesProd helper için app-level cache limiti100
defaultRuntimeOptionsProject-level source'lara merge edilen varsayılan runtime option string'i''
includeDahil edilecek relative HTML path pattern'leri[]
excludeAtlanacak relative HTML path pattern'leri[]
import { defineLuisConfig } from '@lentystyle/core'
export default defineLuisConfig({
ssr: {
mode: 'ssr',
outDirName: 'dist-ssr',
defaultRuntimeOptions: 'performance',
include: ['docs/**'],
},
})

Bu kurulumda defaultRuntimeOptions, auto-discovered source'lara ortak bir baseline verir. Bir source farklı davranmalıysa source-level runtimeOptions ile override edin.


loadLuisSsrProjectConfig(configOrPath?, overrides?)

Section titled “loadLuisSsrProjectConfig(configOrPath?, overrides?)”
import { loadLuisSsrProjectConfig } from '@lentystyle/ssr'
const config = await loadLuisSsrProjectConfig(undefined, { cwd: appDir })

Bu helper:

  • luis.config.mjs dosyasını yükler
  • ssr bloğunu okur
  • request-level config alanlarını çözümler
  • outDirName, maxEntries, include ve exclude gibi project-level default'ları uygular

Validation kuralları:

  • config dosyası gerçek bir ssr object export etmiyorsa throw eder
  • include ve exclude verildiyse string array olmalıdır
  • outDirName boş olamaz ve / ile \ içeremez
{
configPath: '.../luis.config.mjs',
configDir: '.../apps/site',
outDirName: 'dist-ssr',
outDir: '.../apps/site/dist-ssr',
maxEntries: 100,
defaultRuntimeOptions: '',
include: [],
exclude: [],
runtimeOptions: {
debug: false,
performance: false,
map: false,
lazy: false,
worker: 'auto',
},
}

shouldProcessLuisSsrProjectHtmlFile(htmlFilePath, config) üretilen HTML yolunu config.outDir altındaki relative path'e çevirir ve pattern match yapar.

import {
loadLuisSsrProjectConfig,
shouldProcessLuisSsrProjectHtmlFile,
} from '@lentystyle/ssr'
const config = await loadLuisSsrProjectConfig(undefined, { cwd: appDir })
shouldProcessLuisSsrProjectHtmlFile(
`${appDir}/dist-ssr/docs/index.html`,
config,
)

Match kuralları:

  • include boşsa dosya varsayılan olarak dahil edilir
  • include boş değilse en az bir pattern eşleşmelidir
  • sonra exclude eşleşirse dosya reddedilir
ssr: {
include: ['docs/**', 'blog/**'],
exclude: ['blog/drafts/**'],
}

Desteklenen küçük-glob davranışı:

  • *
  • **
  • ?

Path normalization her zaman / kullanır.


  • assetBaseUrl, mode, adapter ve rewritePolicy resolved config içinde taşınır; mevcut request-time SSR akışı bunların her biri için HTML davranışını ayrı ayrı dallandırmaz
  • output.payloadMode şu anda yalnızca 'inline-json'
  • defaultRuntimeOptions project-level metadata'dır; low-level render API bunu doğrudan okumaz
  • include ve exclude yalnızca generated HTML relative path'lerine göre karar verir; source discovery yapmaz