rsbuild-plugin-svg

Rsbuild plugin to load SVG files as Vue components
7,833 4
Install
npm install rsbuild-plugin-svg
Latest Version:0.0.2
Vue:3
License:MIT
Last Updated:Oct 21, 2024
Links: GitHub  ·  npm
Maintainer: fuxichen

rsbuild-plugin-svg

Rsbuild plugin to load SVG files as Vue components, using SVGO for optimization.

Fork by vite-svg-loader

Usage

Install:

npm add rsbuild-plugin-svg -D

Add plugin to your rsbuild.config.ts:

// rsbuild.config.ts
import { pluginSvg } from "rsbuild-plugin-svg";

export default {
  plugins: [pluginSvg()],
};

Import params

URL

SVGs can be imported as URLs using the ?url suffix:

import iconUrl from './my-icon.svg?url'
// 'data:image/svg+xml...'

Raw

SVGs can be imported as strings using the ?raw suffix:

import iconRaw from './my-icon.svg?raw'
// '<?xml version="1.0"?>...'

Component

SVGs can be explicitly imported as Vue components using the ?component suffix:

import IconComponent from './my-icon.svg?component'
// <IconComponent />

Options

Default import config

When no explicit params are provided SVGs will be imported as Vue components by default. This can be changed using the defaultImport config setting, such that SVGs without params will be imported as URLs (or raw strings) instead.

defaultImport

svgLoader({
  defaultImport: 'url' // or 'raw' default: 'component'
})

SVGO Configuration

vite.config.js
svgLoader({
  svgoConfig: {
    multipass: true
  }
})

Disable SVGO

vite.config.js
svgLoader({
  svgo: false
})

Skip SVGO for a single file

SVGO can be explicitly disabled for one file by adding the ?skipsvgo suffix:

import IconWithoutOptimizer from './my-icon.svg?skipsvgo'
// <IconWithoutOptimizer />

Use with TypeScript

If you use the loader in a Typescript project, you'll need to reference the type definitions inside vite-env.d.ts:

/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />

License

MIT.

Related Packages

@vue-devtools-rstack/rsbuild

An Rsbuild plugin for Vue DevTools - feature parity with vite-plugin-vue-devtool...

414 15
storybook-vue3-rsbuild

Storybook for Vue3 and Rsbuild: Develop React Component in isolation with Hot Re...

158,562 157
@vue-devtools-rstack/core

Shared server-side logic for Vue DevTools integration with Rspack/Rsbuild

566 15
@alwaysmeticulous/recorder-plugin

Meticulous plugin for Vite, Webpack, Rspack, Rsbuild, and Nuxt that injects the...

475,823 29
@admirable-oss/mdx-press

Compile .mdx straight to Vue components in Rsbuild, with real dev-server HMR.

171

Version History

Version Released License
0.0.2 MIT
0.0.1 MIT