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

コンポーネントライブラリの公開

There are numerous strategies to publish and distribute your component library to be consumed by external projects. One of the benefits of Stencil is that is makes it easy to generate the various output targets that are right for your use-case.

ノードパッケージマネージャー(NPM)への公開​

The first step and highly recommended step is to publish the component library to NPM. NPM is an online software registry for sharing libraries, tools, utilities, packages, etc. Once the library is published to NPM, other projects are able to add your component library as a dependency and use the components within their own projects.

package.json​

package.jsonファイルの目的は、パッケージのファイルを見つける方法について他のツールに指示を与え、パッケージに関する情報を提供することです。 たとえば、RollupやWebpackなどのバンドラーは、この構成を使用してプロジェクトのエントリファイルを検索します。

An advantage to using the compiler is that it is able to provide help on how to best set up the project for distribution. Below is a common setup found within a project's package.json file:

{
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"es2015": "dist/esm/index.mjs",
"es2017": "dist/esm/index.mjs",
"types": "dist/types/components.d.ts",
"unpkg": "dist/my-project-name/my-project-name.esm.js",
"collection:main": "dist/collection/index.js",
"collection": "dist/collection/collection-manifest.json",
"files": [
"dist/",
"css/",
"loader/"
]
}
プロパティ説明推奨
mainEntry file in the CommonJS module format.dist/index.cjs.js
moduleEntry file in the ES module format. ES modules is the standardized and recommended format.dist/index.js
es2015フレームワークのバンドルで一般的に使用されます。 bundling.dist/esm/index.mjs
es2017フレームワークのバンドルで一般的に使用されます。 bundling.dist/esm/index.mjs
typesEntry file to the project's types.dist/types/components.d.ts
unpkgプロジェクトunpkgCDNへのリクエストのエントリファイル。dist/{NAMESPACE}/{NAMESPACE}.js
filesArray of files that should be included in a npm release.["dist/", "loader/"]

The collection properties are used to allow lazy loading in other Stencil applications.

注記

If you are distributing both the dist and dist-custom-elements, then it's best to pick one of them as the main entry.