1.2.8 β€’ Published 1 month ago

unplugin-svg-sprite v1.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

!Note If you are using Tailwind CSS, I recommend you can try to use svg icons by tailwind plugin by iconify.design, where icons are used as background or mask image.

Also I create a tailwind plugin tailwindcss-plugin-iconify for more easy to use, especially for import local svg icons or import icons from figma.

unplugin-svg-sprite

npm version npm downloads License

🌱 Try it online

πŸŽ‰ Features

  • πŸ¦„ Unified plugin, support Vite/Rollup/Webpack/Nuxt/esbuild
  • ❀️ Framework-agnostic, use whatever framework you like
  • 😎 Import SVG file directly in the source code
  • πŸͺ *Inject dynamic SVG sprite only
  • πŸ˜„ HMR supported (Vite/Webpack)
  • πŸ€– Detect duplicated SVG shapes
  • πŸš€ Auto optimization for unused and duplicated svg shapes (After build)

There is some SVG nodes will make SVG item broken, if use node href property is external link like /svg-sprite-symbol#unplugin. I call it dynamic SVG, because regular SVG can use with external static resource link smoothly.

Fortunately, with the plugin, you can just use injected href property to resolve the situation. Only dynamic SVG sprite will inject to the DOM.

πŸ‘€ Install

npm i unplugin-svg-sprite
// vite.config.ts
import svgSprite from 'unplugin-svg-sprite/vite'

export default defineConfig({
  plugins: [
    svgSprite({
      /* options */
    }),
  ],
})

Example: playground/

// rollup.config.js
import svgSprite from 'unplugin-svg-sprite/rollup'

export default {
  plugins: [
    svgSprite({
      /* options */
    }),
  ],
}

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-svg-sprite/webpack')({
      /* options */
    }),
  ],
}

// nuxt.config.js
export default {
  vue: {
    runtimeCompiler: true,
  },
  // Nuxt 2 move `modules` into `buildModules`
  modules: [
    [
      'unplugin-svg-sprite/nuxt',
      {
        /* options */
      },
    ],
  ],
}

This module works for both Nuxt 2 and Nuxt Vite

// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-svg-sprite/webpack')({
        /* options */
      }),
    ],
  },
}

// esbuild.config.js
import { build } from 'esbuild'
import svgSprite from 'unplugin-svg-sprite/esbuild'

build({
  plugins: [svgSprite()],
})

πŸ—ΊοΈ Road Map

Check todo issues

πŸ“š References

License

MIT License Β© 2023-PRESENT yunsii

1.2.8

1 month ago

1.2.7

8 months ago

1.2.6

9 months ago

1.2.5

9 months ago

1.2.4

9 months ago

1.2.3

9 months ago

1.2.2

9 months ago

1.2.1

9 months ago

1.2.0

9 months ago

1.1.4

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.0

9 months ago

0.1.1

9 months ago

0.1.1-beta.12

9 months ago

0.1.1-beta.11

9 months ago

0.1.1-beta.10

9 months ago

0.1.1-beta.9

9 months ago

0.1.1-beta.8

9 months ago

0.1.1-beta.7

9 months ago

0.1.1-beta.6

9 months ago

0.1.1-beta.5

9 months ago

0.1.1-beta.4

9 months ago

0.1.1-beta.3

10 months ago

0.1.1-beta.2

10 months ago

0.1.1-beta.1

10 months ago

0.1.1-beta.0

10 months ago