stencil-config
This package provides utility functions for creating a set of configurable Stencil components, following best practices.
Ultimately, users of your component library will be able to add the following to their Stencil projects:
src/global/app.ts
; setupConfig;
Component Authors
First, install the package:
npm install stencil-config
Then, add the following to your globalScript
file:
src/global/global.ts (or other)
; declare ;Context.config = createContextConfig'my-namespace';
In order to allow users of your components to pass their own configuration, we'll need to export a setupConfig
function. This takes a few steps, outlined below:
- Create a
src/utils/config.ts
file. This is where oursetupConfig
function and the options interfaces will be exposed from.
; // Add your configuration options here ;;
- Create a file at
src/index.ts
. We just need to re-export oursetupConfig
function, so add the following line:
;
- Create a file named
interface.d.ts
in the root of yoursrc/
directory:
;;
- Update your
package.json
to reflect the new location of yourtypes
file.
Consuming the Config
my-component.tsx
;;