Stencil Config
Stencilでは、すぐに使えるデフォルトの値が設定されているため、多くの場合でstencil.config.tsファイルをカスタマイズする必要はありません。基本的に、設定をできるだけ最小限に抑えることをお勧めします。実際に、stencil.config.tsファイルを削除してもアプリは問題なくコンパイルされます。ですがそれと同時に、この設定を使用してコンパイラを最小限で構成できます。以降は、たくさんある任意の設定プロパティです。
stencil.config.tsの例:
import { Config } from '@stencil/core';
export const config: Config = {
namespace: 'MyApp',
srcDir: 'src'
};
buildDist
default: true (prod), false (dev)
Sets whether or not Stencil will execute output targets and write output to
dist/ when stencil build is called. Defaults to false when building for
development and true when building for production. If set to true then
Stencil will always build all output targets, regardless of whether the build
is in dev or prod mode or using watch mode.
buildDist: true
buildEs5
ES5ビルドを生成するかどうかを設定します。デフォルトは falseです。 trueを設定すると、devモードとprodモードの両方のes5ビルドも作成されます。 buildEs5をprodに設定すると、ES5はprodモードでのみビルドされます。基本的に、アプリをレガシーブラウザー(IE11およびEdge 18以下)で実行する必要がない場合は、デフォルトの buildEs5をfalseに設定して使用しても安全です。これにより、本番ビルドの時間も短縮されます。 es5ビルドの作成に加えて、アプリは__support__レガシーブラウザーのランタイムオプションを有効にすることにも関心がある場合があります。詳細については、 config extras を参照してください。
buildEs5: boolean | 'prod'
bundles
Stencilはデフォルトでアプリケーションを静的に分析し、すべてのコンポーネントがどのように相互接続されているかを示すコンポーネントグラフを生成します。コンポーネントグラフから、アプリ内での相互の使用状況に応じて、コンポーネントをどのようにグループ化するかを最適に判断できます。そうすることで、ネットワークへのリクエストを減らすためにコンポーネントをバンドルすることができます。バンドルはbundlesを使用して手動で生成することもできます。
bundlesは、コンポーネントが遅延ロードされたバンドルにグループ化される方法を表すオブジェクトの配列です。Stencilがバックグラウンドで自動的に処理するため、この構成はほとんど必要ありません。
bundles: [
{ components: ['ion-button'] },
{ components: ['ion-card', 'ion-card-header'] }
]
devServer
Dev-Server docsをご覧ください。
enableCache
デフォルト: true
Stencilは再ビルドを高速化するために、ビルド結果をキャッシュします。この機能を無効にするには、enableCacheをfalseに設定します。
enableCache: true
extras
Extras docsをご覧ください。
globalScript
global scriptは、ライブラリやアプリが読み込まれる前に1回実行されるため、外部サービスへの接続の設定や、使用しているライブラリのビルドなどを行うことができます。
実行されるコードは、global scriptによってエクスポートされるデフォルトの関数内に配置する必要があります。global scriptのすべてのコードが、エクスポートされる関数でラップされていることを確認してください。
global scriptのオプションは、ファイルパスを文字列として受け取ります。
export default function() { // or export default async function()
initServerConnection();
}
The exported function can also be async.
globalStyle
Stencilは、多くのコンポー ネントをアプリにコンパイルするために伝統的に使用されており、各コンポーネントには独自のコンパートメント化されたスタイルが付属しています。ただし、すべてのコンポーネントとWebサイトで"グローバル"なスタイルを使用することは今でも一般的です。グローバルCSSファイルは、CSS Variablesを定義するのに役立ちます。
Additionally, the globalStyle config can be used to precompile styles with Sass, PostCSS, etc.
次は、app.cssという名前のグローバルcssファイルを含むフォルダー構造の例です。
src/
components/
global/
app.css
global styleは、ファイルパスを文字列で設定します。このビルドによる出力は、buildDirに送られます。次の例では、www/build/app.cssに保存されます。
globalStyle: 'src/global/app.css'
アプリでグローバルスタイルを使用する方法については、styling docsをご覧ください。
hashedFileNameLength
デフォルト: 8
hashedFileNameLengthはファイル名のハッシュが何文字であるべきかを指定します。hashFileNamesがtrueに設定されていて、productionビルドの時のみ有効です。
hashedFileNameLength: 8
hashFileNames
デフォルト: true
productionビルドでは、生成された各ファイルのコンテンツはハッシュ化され、ハッシュ化された値がファイル名として使用されます。コンテンツがビルド間で更新されない場合、同じファイル名を受け取ります。コンテンツが更新されると、ファ イル名が異なります。これにより、デプロイされたアプリはビルドディレクトリを"永続的にキャッシュ"し、Content Delivery Network(CDN)を最大限に活用して大量のファイルをキャッシュすることで、高速なアプリを実現できます。
hashFileNames: true
hydratedFlag
When using the lazy build Stencil has support for automatically applying a class or attribute to a component and all of its child components when they have finished hydrating. This can be used to prevent a flash of unstyled content (FOUC), a typically-undesired 'flicker' of unstyled HTML that might otherwise occur during component rendering while various components are asynchronously downloaded and rendered.
By default, Stencil will add the hydrated CSS class to elements to indicate
hydration. The hydratedFlag config field allows this behavior to be
customized, by changing the name of the applied CSS class, setting it to use an
attribute to indicate hydration, or changing which type of CSS properties and
values are assigned before and after hydrating. This config can also be used to
turn off this behavior by setting it to null.
If a Stencil configuration does not supply a value for hydratedFlag then
Stencil will automatically generate the following default configuration:
const defaultHydratedFlag: HydratedFlag = {
hydratedValue: 'inherit',
initialValue: 'hidden',
name: 'hydrated',
property: 'visibility',
selector: 'class',
};
If hydratedFlag is explicitly set to null, Stencil will not set a default
configuration and the behavior of marking hydration with a class or attribute
will be disabled.
hydratedFlag: null | {
name?: string,
selector?: 'class' | 'attribute',
property?: string,
initialValue?: string,
hydratedValue?: string
}
The supported options are as follows:
name
default: 'hydrated'
The name which Stencil will use for the attribute or class that it sets on elements to indicate that they are hydrated.
name: string
selector
default: 'class'
The way that Stencil will indicate that a component has been hydrated. When
'class', Stencil will set the name option on the element as a class, and
when 'attribute', Stencil will similarly set the name option as an
attribute.
selector: 'class' | 'attribute'
property
default: 'visibility'
The CSS property used to show and hide components. This defaults to the CSS
visibility property. Other possible CSS properties might include display
with the initialValue setting as none, or opacity with the initialValue
as 0. Defaults to visibility.
property: string
initialValue
default: 'hidden'
This is the value which should be set for the property specified by property
on all components before hydration.
initialValue: string