跳到主要内容
FarmFarm
Version: 2.x(最新)
本页目录

@farmfe/plugin-svgr

A Rust Farm plugin that transforms SVG files into React components.

Installation

javascript
npm install -D @farmfe/plugin-svgr
javascript
yarn add -D @farmfe/plugin-svgr
javascript
pnpm add -D @farmfe/plugin-svgr

Usage

Register the plugin in farm.config.ts:

ts
import { defineConfig } from "@farmfe/core";
import svgr from "@farmfe/plugin-svgr";

export default defineConfig({
  plugins: [
    svgr({
      include: ["src/**/*.svg"],
      exclude: ["src/icons/*.svg"],
      defaultStyle: { fill: "currentColor" },
      defaultClass: "svg-icon",
    }),
  ],
});

Then import SVG files as React components:

jsx
import Logo from "./logo.svg";

export function App() {
  return <Logo width={50} height={50} />;
}

Options

  • include?: string[] — SVG file patterns to transform. Defaults to ["**/*.svg"].
  • exclude?: string[] — SVG file patterns to skip.
  • defaultClass?: string — default class name added to the generated SVG.
  • defaultStyle?: object — default style object added to the generated SVG.

SVG imports with ?raw, ?url, ?inline, or ?img=true are ignored by this plugin.

100%

Drag or pinch to explore. Keyboard: + / − zoom, arrows pan, 0 resets, Esc closes.