Create Component Plugin
You can build a component plugin to publish your own custom components, or to make existing open source component libraries easily available for Evidence users.
The easiest way to get started is from the example component library on GitHub, with a live demo of the components here.
Basic Steps
- Clone the Evidence Labs example repo
- Add your components to the
src/lib
directory in place of the existing components - Add pages in the
pages
directory to show your components, in place of the existing pages - Set up component exporting (see section below)
- Test that your components work by running the dev server with
npm run dev
and inspecting the pages you created - Edit the name in
package.json
from@evidence-dev/labs
toyour-plugin-name
and set the version to0.0.1
- Publish to npm with
npm publish
(You will need to be logged in to an npm account) - Install your plugin by following the steps here
- Make changes to your plugin and republish with
npm publish
- note that you need to bump the version number inpackage.json
each time you do this
Component Exporting
Plugins must "export" their components to make them available to your Evidence apps.
There are 2 ways to set up component exporting in your plugin:
- Module Exports (recommended)
- Manifest - this method can be used in cases when a large component library already exists
Note that these are mutually exclusive, and the manifest takes priority.
Module Exports
When writing a plugin from scratch, this is the preferred method.
Steps
- Add the following to each component in your plugin to "flag" the component as something that should be imported as part of the plugin (at the top of the component's
.svelte
file)
<script context="module">
export const evidenceInclude = true;
</script>
- Add an
index.js
file to thesrc/lib
directory - Add one line to
index.js
per component in your plugin. This will export the components, making them available in Evidence:export {default as ComponentOne} from "./ComponentOne"; export {default as ComponentTwo} from "./ComponentTwo";
Manifest
If you would prefer not to flag each individual component file, another approach is to maintain an evidence.manifest.yaml
file. The structure of the file is a single array of component names.
Steps
- Add an
evidence.manifest.yaml
to yoursrc/lib
directory - Add a line to the file for each component in your plugin:
components: - ComponentOne - ComponentTwo
- Add an
index.js
file to thesrc/lib
directory - Add one line to
index.js
per component in your plugin. This will export the components, making them available in Evidence:export {default as ComponentOne} from "./ComponentOne"; export {default as ComponentTwo} from "./ComponentTwo";
Promoting Your Plugin
If you are building a plugin for other Evidence users, let us know in Slack and we can share it with the community.