Loader Bundle Output Target
Renamed from dist in Stencil v4. Run stencil migrate --dry-run to preview updating an existing config automatically.
The loader-bundle type generates the component(s) as a reusable, lazy-loading library, such as Ionic. Every component compiles to its own chunk, and the loader only fetches a given chunk once that component actually appears in the DOM - the browser downloads just the components a page uses, not the whole library up front.
Publishing this output requires the right package.json fields pointing at it - see Lazy Loading in the publishing guide for the exact exports map.
outputTargets: [
{
type: 'loader-bundle'
}
]
構成
dir
default: dist/loader-bundle
The public distribution directory. This directory is built and rebuilt directly from the source files. Since this is a build target, all files will be deleted and rebuilt after each build, so it's best to always copy source files into this directory. It's recommended that this directory not be committed to a repository.
buildDir
default: '' (the root of dir)
Where the lazy-loaded chunks themselves are written, relative to dir. Set this to '../' if you want the bundle's CDN-facing path to remain at your project's dist/ root rather than moving to dist/loader-bundle/.
cjs
default: false
Whether to also generate CommonJS bundles, written to a cjs/ subdirectory. As of Stencil v5, loader-bundle only generates ESM output by default - set this to true to restore CommonJS output.
copy
default: undefined
An array of copy tasks to be executed during the build process.
empty
default: true
By default, before each build the dir directory will be emptied of all files. To prevent this directory from being emptied, change this value to false.
loaderPath
default: loader (relative to dir)
Provide a custom path for the loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading. Read more about the loader directory below.
Renamed from esmLoaderPath in Stencil v4 - and its path is now resolved relative to dist/loader-bundle instead of dist. Pass loaderPath: '../' to reproduce the old resolved path.
If you don't use a custom exports map, users would have to import the loader script via:
import { defineCustomElements } from 'stencil-library/dist/loader-bundle/loader'