Skip to content

a vite plugin replaces img tags with svg content when the src attribute points to an SVG file and support theme color switch

Notifications You must be signed in to change notification settings

ylw5/vite-plugin-svmg

Repository files navigation

vite-plugin-svmg

This Vite plugin replaces img tags with svg content when the src attribute points to an SVG file, and allows for configuration options to costomize svg color to match the theme.

Installation

npm install vite-plugin-svmg -D

Usage

import { defineConfig } from 'vite'
import svmg from 'vite-plugin-svmg'

export default defineConfig({
  plugins:[
    svmg({
      color: {
        root: {
          white: '#1d1d1d',
        },
        dark: {
          white: '#ffffff',
        },
      },
    })
  ]
})

Your component:

<template>
  <div>
    <img src="./assets/hello.svg" />
  </div>
</template>

toggle theme:

document.documentElement.classList.toggle('dark')

TODO:

  • support resolve src with alias
  • compatible with more theme switch ways
  • synchronize img tag attributes or style to svg content

About

a vite plugin replaces img tags with svg content when the src attribute points to an SVG file and support theme color switch

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published