Vite plugin for dynamically changing theme colors at runtime. Version 0.8.6 requires Vite >=2.0.0 and Node >=12.0.0. It extracts specified color variables from CSS output at build time, generating a separate theme stylesheet (app-theme-style.css) that can be dynamically swapped via JavaScript. Unlike CSS custom properties or runtime CSS-in-JS approaches, this plugin works with static CSS and supports deep customization options like custom selector resolution and variable extraction logic. Released under MIT, maintained by Vben Admin team. Not actively updated since mid-2023.
npm install vite-plugin-themeVerified import paths — ran on the pinned version, not inferred.
Configures vite-plugin-theme in a Vite + Vue project, specifying colors to extract and dynamic injection options.
Ensure all theme-dependent styles are in CSS files (not inline) for extraction to work.
Include the exact full color string (e.g., '#1890ff' not '#189') in colorVariables array.
Use injectTo: 'head' or 'body-prepend' to control load order, or ensure main CSS loads before this file.
Test compatibility with your Vite version; consider using CSS custom properties for modern themes.
Use Vite 2.x or fork the plugin to adapt to newer Vite versions.
Filter out virtual CSS modules in the plugin's transform hook or avoid using inline CSS from virtual modules.