Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/korywka/rollup-plugin-svg-import
Import SVG files in javascript
https://github.com/korywka/rollup-plugin-svg-import
rollup-plugin svg
Last synced: 29 days ago
JSON representation
Import SVG files in javascript
- Host: GitHub
- URL: https://github.com/korywka/rollup-plugin-svg-import
- Owner: korywka
- Created: 2019-09-24T09:28:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-19T12:43:53.000Z (12 months ago)
- Last Synced: 2024-05-15T06:57:13.502Z (7 months ago)
- Topics: rollup-plugin, svg
- Language: JavaScript
- Homepage:
- Size: 87.9 KB
- Stars: 14
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome - svg-import - Import SVG files as SVG DOM Node or string. (Plugins / Other File Imports)
README
# rollup-plugin-svg-import
Import `.svg` images in javascript files
## Installation
```sh
npm install --save-dev rollup-plugin-svg-import
```## Usage
By default SVG import returns a `` DOM node:
```js
import icon from './icon.svg';document.body.appendChild(icon());
```To import SVG image as a string, e.g. for SSR, set `stringify` to `true`:
```js
import icon from './icon.svg';document.body.innerHTML += icon;
```## Configuration
```javascript
// 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
}),
],
};
```