Gem 一覧へ戻る
korywka/rollup-plugin-svg-import(新しいタブで開きます)
主要言語: JavaScript
Import SVG files in javascript
- star 数
- 14
- watcher 数
- 1
- fork 数
- 1
- issue 数
- 1
- 最終更新
- 2024/09/24
主要言語: JavaScript
Import SVG files in javascript
Import .svg images in javascript files
npm install --save-dev rollup-plugin-svg-import
By default SVG import returns a <svg> DOM node:
import icon from './icon.svg'; document.body.appendChild(icon());
To import SVG image as a string, e.g. for SSR, set stringify to true:
import icon from './icon.svg'; document.body.innerHTML += icon;
// rollup.config.js import svg from 'rollup-plugin-svg-import'; export default { input: './input.js', output: { file: './output.js', format: 'esm', }, plugins: [ svg({ /** * If `true`, instructs the plugin to import an SVG as string. * For example, for Server Side Rendering. * Otherwise, the plugin imports SVG as DOM node. */ stringify: true }), ], };