项目作者: codefeathers

项目描述 :
Import SVG files as Svelte Components
高级语言: JavaScript
项目地址: git://github.com/codefeathers/rollup-plugin-svelte-svg.git
创建时间: 2020-01-06T15:16:33Z
项目社区:https://github.com/codefeathers/rollup-plugin-svelte-svg

开源协议:MIT License

下载


[!CAUTION]
This package is DEPRECATED. Svelte supports importing SVGs natively now. See: https://svelte.dev/playground/86553af5c35449ab88e34f1e50eb298f?version=5.30.1

rollup-plugin-svelte-svg

Import SVG files as Svelte Components

Note: rollup-plugin-svelte-svg was rewritten from scratch recently, and no longer exposes Svelte options ({ dev, generate }) since we now delegate compilation to the Svelte plugin that’s loaded after us. You should remove these options since they have no effect.

This is a nonbreaking change for most users, however if you do face a problem, raise an issue.

Contents

Installation

  1. # using npm
  2. npm i -D rollup-plugin-svelte-svg
  3. # using yarn
  4. yarn add -D rollup-plugin-svelte-svg
  5. # using pnpm
  6. pnpm i -D rollup-plugin-svelte-svg

Usage

Simply call svelteSVG before svelte in your rollup config.

Svelte

  1. // rollup.config.js
  2. import { svelteSVG } from "rollup-plugin-svelte-svg";
  3. export default {
  4. entry: "src/input.js",
  5. dest: "dist/output.js",
  6. plugins: [
  7. svelteSVG({
  8. // optional SVGO options
  9. // pass empty object to enable defaults
  10. svgo: {}
  11. }),
  12. ],
  13. ...
  14. }

Sapper

  1. // rollup.config.js
  2. import { svelteSVG } from "rollup-plugin-svelte-svg";
  3. export default {
  4. client: {
  5. plugins: [
  6. svelteSVG({
  7. // optional SVGO options
  8. // pass empty object to enable defaults
  9. svgo: {},
  10. }),
  11. ],
  12. ...
  13. },
  14. server: {
  15. plugins: [
  16. svelteSVG({
  17. // optional SVGO options
  18. // pass empty object to enable defaults
  19. svgo: {}
  20. }),
  21. ],
  22. ...
  23. },
  24. }

Vite

  1. // vite.config.js
  2. import { defineConfig } from "vite";
  3. import { svelteSVG } from "rollup-plugin-svelte-svg";
  4. export default defineConfig({
  5. ...
  6. plugins: [
  7. svelteSVG({
  8. // optional SVGO options
  9. // pass empty object to enable defaults
  10. svgo: {},
  11. // vite-specific
  12. // https://vitejs.dev/guide/api-plugin.html#plugin-ordering
  13. // enforce: 'pre' | 'post'
  14. enforce: "pre",
  15. }),
  16. ...
  17. ],
  18. });

You can then import svg in your JS thusly:

  1. <script>
  2. import Logo from "./logo.svg";
  3. </script>
  4. <Logo width=20 ></Logo>

Credits

License

MIT