Write a plugin
This example injects a global component to show how to define and use plugins.
1. Define a plugin
plugin.ts
Example.tsx
A plugin is usually a function that receives optional plugin parameters and returns an object containing the plugin name and other config.
In the example above, we define a plugin named plugin-example. It defines a global environment variable, process.env.SLUG, during the build phase and injects the global component Example.tsx into the page.
2. Use a plugin
Register plugins via plugins in rspress.config.ts:
rspress.config.ts
The Example component is then injected into the page, and the component can access process.env.SLUG.