Bundler Plugin
@stencil/unplugin compiles Stencil components inside another bundler's build: Vite, webpack, Rspack, Rollup or esbuild. Each component file becomes a custom element that registers itself when it's imported, with no separate Stencil build. Use it to write Stencil components directly in an app, such as a framework app built with Vite or webpack.
The Vitest integration uses the same plugin, to compile components as tests import them.
The bundler plugin is new in Stencil v5, and hasn't been used as widely as a Stencil build. If a component behaves differently with the plugin than in a Stencil build, please open an issue.
The plugin doesn't run output targets, so it doesn't generate framework wrappers, server rendering or the other outputs of a component library. To publish a library, build it with Stencil.
Setup
Install the plugin alongside Stencil:
- npm
- Yarn
- pnpm
npm install --save-dev @stencil/unplugin @stencil/core
yarn add --dev @stencil/unplugin @stencil/core
pnpm add --save-dev @stencil/unplugin @stencil/core
Add it to your bundler's config. For Vite:
import { defineConfig } from 'vite';
import { stencilVite } from '@stencil/unplugin';
export default defineConfig({
plugins: [stencilVite()],
});
For the other bundlers, use stencilWebpack, stencilRspack, stencilRollup or stencilEsbuild in the same way.