rollup-plugin-web-components
This plugin provides a loader for single file web components, and injects their templates into html files.
Install
yarn add rollup-plugin-web-components --dev
or
npm install rollup-plugin-web-components -D
Usage
This plugin only injects component templates to assets emitted with the emitFile() plugin context method and having .html
as extension.
The following example uses rollup-plugin-emit-files to emit html pages to rollup bundle.
// rollup.config.js // ... plugins:
<!-- src/components/x-button.html !--> <!-- The style element can be either inside or outside the template element !-->
// src/index.js customElements
<!-- src/pages/index.html !--> Page with web components hey
The output folder will contain the following index.html
file:
Page with web components hey
No matter wether the style element is inside or outside the template element:
- It will always be inside when injected into html
- It will always be removed and exported separatly when imported from javascript
Options
extension
The extension which must be loaded with the web-components loader.
Default: '.html'
inject
If set to true, the plugin will inject all templates from imported components to all html files emitted in the rollup bundle.
Default: true