traintocode

Using Your Plugin in a Vite Project

Now that you’ve written a basic Vite plugin, it’s time to see it in action.

Vite plugins are just functions—so using one is as simple as importing it and adding it to your vite.config.ts file inside the plugins array.

Here’s how you can do that in a real Vite project:

Step-by-Step:

  1. Export your plugin from its own file (e.g., plugins/myPlugin.ts)
  2. Import it inside vite.config.ts
  3. Add it to the plugins array
Exercise

Use your new Vite plugin in this vite.config.ts file

    You cannot do the coding exercises on this device, visit this page on a larger screen.
    vite-config.ts
    Loading...
    myPlugin.ts
    Loading...