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

出力ターゲット

コンパイラのより強力な機能の1つは、コンポーネントが使用される 方法 に応じてさまざまなビルドを生成する機能です。 Stencilは、アプリのソースを取得して、httpサーバーにデプロイするWebアプリ、npmで配布するサードパーティコンポーネントの遅延読み込みライブラリ、またはVanillaJSのカスタムエレメントなど、多数のターゲットにコンパイルできます。 デフォルトでは、Stencilの出力ターゲットタイプは wwwであり、これはWebアプリに最適です。

Output Target Types:​

例:​

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

export const config: Config = {
outputTargets: [
{
type: 'dist'
},
{
type: 'www'
}
]
};

ディファレンシャルバンドリング​

「差分バンドリング」をサポートするために、コンパイラーが多数のバンドルを自動的に生成することに注意することも重要です。 これが意味するのは、本番ビルド中に、ステンシルは同じソースコードから最新のブラウザーとレガシーブラウザー(IE11)の両方のコードを生成するということです。 ディファレンシャルバンドルの利点は、最新のブラウザーがすべてのポリフィルと肥大化したレガシーJavaScriptを回避し、ブラウザーに既に組み込まれている最新のAPIを使用できることです。

以下の例では、2つのスクリプトタグがありますが、ユーザーが要求するのはそのうちの1つだけです。 IE11ユーザーの場合、ES5構文ですべてのポリフィルを含むapp.jsファイルをダウンロードします。 最新のブラウザを使用しているユーザーは、ESモジュール、動的インポート、非同期/待機、クラスなどの最新のJavaScript機能を使用する app.esm.jsファイルのみをダウンロードします。

注記

buildEs5 must be set to true to generate the IE11 ES5 file

<script type="module" src="/build/app.esm.js"></script>
<script nomodule src="/build/app.js"></script>

Docs Auto-Generation​

As apps scale with more and more components, and team size and members continue to adjust over time, it's vital all components are well documented, and that the documentation itself is maintained. Maintaining documentation is right up there with some of the least interesting things developers must do, but that doesn't mean it can't be made easier.

Throughout the build process, the compiler is able to extract documentation from each component, to include JSDocs comments, types of each member on the component (thanks TypeScript!) and CSS Variables (CSS Custom Properties).

コンポーネントプロパティドキュメントの例:​

@Propに説明を追加するには、前の行にコメントを追加するだけです。

/** (optional) The icon to display */
@Prop() iconType = "";

CSSの例​

Stencilは、cssまたはscssファイル内のjsdocスタイルのコメントを介してCSS変数を指定すると、CSS変数も文書化します。

 :root {
/**
* @prop --primary: プライマリヘッダーの色
*/
--primary: blue;
}