Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundling stencil component with webpack

Do anyone know how to bundling the web component created with stencil using webpack. I have multiple stencil components and need to create a bundle so that i can use it in other projects.

like image 314
sijo jose Avatar asked Sep 03 '19 09:09

sijo jose


People also ask

Does stencil use Webpack?

Stencil provides a Webpack plugin that makes it easy to include web components that have been built using Stencil in your Webpack built application.

How do you bundle on a Webpack?

You can bundle your JavaScript using the CLI command by providing an entry file and output path. Webpack will automatically resolve all dependencies from import and require and bundle them into a single output together with your app's script.

What is defineCustomElements?

Calling defineCustomElementsA component collection built with Stencil includes a main function that is used to load the components in the collection. That function is called defineCustomElements() and it needs to be called once during the bootstrapping of your application.


2 Answers

Ionic has developed a StencilPlugin for webpack, which allows to easily import components using the webpack bundler.

You may also be interested in this excellent article which explains in more details how to use the plugin.

like image 133
Sébastien Rosset Avatar answered Oct 23 '22 12:10

Sébastien Rosset


The stencil build command normally bundles everything for you into the components.js file (or whatever your stencil config's namespace value is). So you shouldn't need to create your own bundle. If you are finding problems with the Stencil-built bundle, maybe have a look at https://stenciljs.com/docs/module-bundling.

like image 45
G. Tranter Avatar answered Oct 23 '22 14:10

G. Tranter