メインコンテンツまでスキップ
バージョン: v3

Prerender Config for Static Site Generation (SSG)

As of 1.13.0, the optional prerender config can be used while prerendering a www output target. The prerender.config.ts file can further update the parsed document of each page, before it is serialized to HTML.

Within stencil.config.ts, set the path to the prerendering config file path using the prerenderConfig property, such as:

import { Config } from '@stencil/core';

export const config: Config = {
outputTargets: [
{
type: 'www',
baseUrl: 'https://stenciljs.com/',
prerenderConfig: './prerender.config.ts',
}
]
};

次に、 prerender.config.tsファイル内で、PrerenderConfigインターフェースを使用して configオブジェクトをエクスポートする必要があります。

import { PrerenderConfig } from '@stencil/core';
export const config: PrerenderConfig = {
...
};
コンフィグ説明デフォルト値
afterHydrate(document, url)各 documentがハイドレイトされた後、HTML文字列にシリアル化される前に実行します。 フックには documentとそのURLが渡されます。
beforeHydrate(document, url)各 ドキュメントがハイドレイトされる前に実行します。 フックには「ドキュメント」が渡され、「URL」になります。
afterSerializeTemplate(html)テンプレートDocumentオブジェクトがHTML形式の文字列にシリアル化された後に実行されます。 事前にレンダリングされたすべてのページのベーステンプレートとして使用されるHTML文字列を返します。
beforeSerializeTemplate(document)テンプレートDocumentオブジェクトがHTML形式の文字列にシリアル化される前に実行されます。 シリアル化されるドキュメントを返します。これは、事前にレンダリングされたすべてのページのベーステンプレートhtmlになります。
canonicalUrl(url)事前にレンダリングされたすべてのページの <head>に配置される正規の <link>タグを生成するために使用されるフック。 nullを返しても、正規のURLタグはページに追加されません。
crawlUrls事前レンダリング中に、 <a href>要素内で見つかった同一生成元のURLをクロールします。true
entryUrls事前レンダリングを開始するURL。 デフォルトでは、 /のルートURLが使用されます。['/']
filterAnchor(attrs, base)指定された <a>要素をクロールするかどうかにかかわらず trueを返します。
filterUrl(url, base)指定されたURLを事前にレンダリングする必要があるかどうかにかかわらず、「true」を返します。
filePath(url, filePath)事前にレンダリングされたHTMLコンテンツが書き込まれるファイルパスを返します。
hydrateOptions(url)個々の事前レンダリングされたページに使用するハイドレートオプションを返します。
loadTemplate(filePath)テンプレートファイルの内容を返します。 テンプレートは、事前にレンダリングされたすべてのページに使用されるベースHTMLです。
normalizeUrl(href, base)指定された文字列と現在のページのベースURLからページのURLを正規化するために使用されます。 アンカーの href属性値を読み取り、それをURLに正規化するときに主に使用されます。
staticSiteStatic Site Generated (SSG). Does not include Stencil's client-side JavaScript, custom elements or preload modules.false
trailingSlashIf the prerendered URLs should have a trailing "/"" or notfalse

個々のページのハイドレートオプション​

prerender.config.tsを使用した事前レンダリングプロセス全体の設定に加えて、次のこともできます。 set individual hydrate options per each page. The hydrateOptions(url) hook can be used to further configure each page. Below is an example of the prerender config with the hydrateOptions() hook, which returns options for each page.

import { PrerenderConfig } from '@stencil/core';

export const config: PrerenderConfig = {
hydrateOptions(url) {
return {
prettyHtml: true
};
}
};


オプション説明デフォルト値
addModulePreloads最終的に要求されるモジュールに <link rel =" modulepreload ">を追加します。true
approximateLineWidthSets an approximate line width the HTML should attempt to stay within. Note that this is "approximate", in that HTML may often not be able to be split at an exact line width. Additionally, new lines created is where HTML naturally already has whitespace, such as before an attribute or spaces between words.100
canonicalUrl<head>内の <link rel ="canonical">タグに href属性を設定します。値が定義されていない場合は、正規リンクタグが <head>に含まれていないことを確認します。
clientHydrateAnnotationsInclude the HTML comments and attributes used by the client-side JavaScript to read the structure of the HTML and rebuild each component.true
constrainTimeoutssetTimeout()を1msに制限しますが、それでも非同期です。また、 setInterval()の起動は1回のみで、1ミリ秒に制限されています。true
cookiedocument.cookieを設定します
directionトップレベルの <html>に dir属性を設定します。
excludeComponentsComponent tag names listed here will not be prerendered, nor will hydrated on the client-side. Components listed here will be ignored as custom elements and treated no differently than a <div>.
inlineExternalStyleSheets代わりに、 <link rel ="stylesheet">の外部スタイルシートが <style>要素にインライン化されます。true
languageトップレベルの <html>に lang属性を設定します。
maxHydrateCount1ページでハイドレートするコンポーネントの最大数。300
minifyScriptElements<script>要素内のJavaScriptコンテンツを縮小します。true
minifyStyleElements<style>要素内のCSSコンテンツを縮小します。true
prettyHtmlHTMLを適切にインデントされた形式でフォーマットします。false
referrerdocument.referrerを設定します。
removeAttributeQuotes可能な場合は、属性値から引用符を削除してください。true
removeBooleanAttributeQuoteshiddenやcheckedなどの標準化された boolean属性から=""を削除します。true
removeEmptyAttributes値が空の場合は、次の標準化された属性を削除します: class、dir、 id、lang、および name、title。true
removeHtmlCommentsHTMLコメントを削除します。true
removeScriptsdocumentで見つかったすべての<script>要素を削除します。false
removeUnusedStylesdocument内の要素で使用されていないCSSを削除します。true
resourcesUrlランタイムがアセットディレクトリなどのリソースに使用するURL。
runtimeLoggingランタイムコンソールログをNodeJSプロセスに出力します。false
staticComponentsComponent tags listed here will only be prerendered or server-side rendered and will not be client-side hydrated. This is useful for components that are not dynamic and do not need to be defined as a custom element within the browser. For example, a header or footer component would be a good example that may not require any client-side JavaScript.
staticDocumentdocument全体は静的でなければなりません。これは、サイト全体ではなく、静的である必要がある特定のページに役立ちます。サイト全体を静的にする必要がある場合は、代わりにprerender構成の staticSiteプロパティを使用してください。特定のコンポーネントのみを静的にする必要がある場合は、代わりに staticComponentsを使用してください。false
timeoutタイムアウトエラーがスローされるまで、ページのレンダリングが終了するまで待機するミリ秒数。15000
titledocument.titleを設定します
urllocation.hrefを設定します
userAgentnavigator.userAgentを設定します