Giter Site home page Giter Site logo

limingziqiang / vite-plugin-theme Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yuliang-lee/vite-plugin-theme

0.0 0.0 0.0 211 KB

Vite plugin for dynamically changing the theme color of the interface

License: MIT License

JavaScript 4.61% TypeScript 95.39%

vite-plugin-theme's Introduction

@xlaoyu/vite-plugin-theme

原作者的 vite-plugin-theme 不再维护, 所以 fork 新仓库解决一些 vite 适配问题

English | 中文

npm node

Vite plugin for dynamically changing the theme color of the interface

After vite processes the css and dynamically analyzes the color value in the css text that matches the plug-in configuration, extract the specified color style code from all output css files. And create a app-theme-style.css file containing only color styles, dynamically insert it into the specified position (the bottom of the default body), and then replace the custom style/component library style color used with the new color, In order to achieve the purpose of dynamically changing the theme color of the project

Install (yarn or npm)

node version: >=12.0.0

vite version: >=2.0.0

yarn add @xlaoyu/vite-plugin-theme -D

or

npm i @xlaoyu/vite-plugin-theme -D

Usage

  • Config plugin in vite.config.ts. In this way, the required functions can be introduced as needed
import { defineConfig, Plugin } from 'vite';
import vue from '@vitejs/plugin-vue';

import { viteThemePlugin, mixLighten, mixDarken, tinycolor } from '@xlaoyu/vite-plugin-theme';

export default defineConfig({
  plugins: [
    vue(),
    viteThemePlugin({
      // Match the color to be modified
       colorVariables: [],
    });
  ],
});

Options

viteThemePlugin(Options)

Options

param type default desc
colorVariables string[] - If css contains the color value in the array, css will be extracted
wrapperCssSelector string - Universal outer selector. You can pass in'body' and other selectors to increase the level
resolveSelector (selector:string)=>string - Custom selector conversion
customerExtractVariable (css:string)=>string - Custom css matching color extraction logic
fileName string app-theme-style.hash.css File name output after packaging
injectTo body or head or body-prepend body The css loaded in the production environment is injected into the label body
isProd boolean true 默认不用设置,效果就可以切换主题, 设置为 false 则生产环境禁止切换主题

Sample project

Vben Admin

Reference project

License

MIT

vite-plugin-theme's People

Contributors

anncwb avatar vben-admin avatar yuliang-lee avatar zeyanguo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.