4.2.0 • Published 6 months ago

vite-plugin-svgr v4.2.0

Weekly downloads
188
License
MIT
Repository
github
Last release
6 months ago

vite-plugin-svgr

npm

Vite plugin to transform SVGs into React components. Uses svgr under the hood.

Installation

# npm
npm install --save-dev vite-plugin-svgr

# yarn
yarn add -D vite-plugin-svgr

# pnpm
pnpm add -D vite-plugin-svgr

Usage

// vite.config.js
import svgr from "vite-plugin-svgr";

export default {
  // ...
  plugins: [svgr()],
};

Then SVG files can be imported as React components:

import Logo from "./logo.svg?react";

If you are using TypeScript, there is also a declaration helper for better type inference:

/// <reference types="vite-plugin-svgr/client" />

Options

svgr({
  // svgr options: https://react-svgr.com/docs/options/
  svgrOptions: {
    // ...
  },

  // esbuild options, to transform jsx to js
  esbuildOptions: {
    // ...
  },

  // A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should include.
  include: "**/*.svg?react",

  //  A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
  exclude: "",
});

If you want to enable SVGO you can install @svgr/plugin-svgo and use following options to enable and configure it:

svgr({
  svgrOptions: {
    plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"],
    svgoConfig: {
      floatPrecision: 2,
    },
  },
  // ...
});

License

MIT

@une/cli@inv3rse/react-sdkhorizon-design-system@infinitebrahmanuniverse/nolb-vite-plugin-s@nexatlas-os/nexds-webcro-joon-frontend-components-storymy-first-library-for@yamcodes/uiplop-dms@everything-registry/sub-chunk-3061cloud-air-components@beardeddudes-dev/vite@beardeddudes-dev/vite-configgic_frontendgsk-frontend-componentsdropuidyzz-react-tree-selectfeedbacky-module-systemies-dynamic-inputlowcoder-cliados-componentsipts-ds-system-demoinstagram-carouselkvikna-designsystemkronoos-uikyberswap-widgetsjusta-clientmailcraftmainstack-design-systemnano-designmonk_uimf-core-uipoletto-bookstorepolicyengine-clientpod-sustainability-analysis-normosp-uipyp-brick-builderopenblocks-clireact-vite-styled-appreact-toolkit-ldvreact-deadly-simple-carouselreact-flags-componentprueba_dinamico_libreriareact-cardflee-animrmscomponentsrlawodus-react-ui-vitetest-web-shared-componentstest-gugassstesting-test-testestui-library-rodrigosupertonestitch-component-clistores_in_store_test_npmtable-react-component-librarytailwind-admintalentorg-profile-editortermblockterho-new-buttonuser-sentimentsspacer-ui-componentsspacer-ui-kitsbwb-dssbx-chat-botvpdchatbottesttrack-1-design-systemwaggle-design-systemxverse-iconxing-react-ui@beardeddudes/vite-config@big-components/ui@bixi-design/builder@shop-one/builder-utils@axos-web-dev/shared-components@appkit/dek-lib@armco/armory-react-components@ariga/atlas-website@darkobits/tsx@de-mklinger/react-slideshowcollaborative-form@dripui/react@elyspio/vite-eslint-config@entropik/decode-insights-chartscufc-uideliveree_auth_popupdesign-react-vite@bn-digital/vitecounter-test-datagile@edsc/metadata-preview@emilgadzhiyev/tree-menu@exogee/graphweaver-builder@hrnet-aj/data-tabledoyeon-storybook-component@graphiql/plugin-utils@hyperloop-upv/common-front@iclubs-packages/design-systembx-test-ktytdcnigb@clarke-energia/foton@cryptohubltd/kyberswap-widget@cro-project/cro-frontend-components@civic/react-commons
4.2.0

6 months ago

3.3.0

8 months ago

4.1.0

7 months ago

4.0.0

8 months ago

3.2.0

1 year ago

3.1.0

1 year ago

3.0.0

1 year ago

2.3.0

1 year ago

2.4.0

1 year ago

2.2.2

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.5.0

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago