0.2.0 • Published 5 years ago
rollup-plugin-svgi v0.2.0
rollup-plugin-svgi
Use SVG files in JSX.
Why?
Installation
npm
npm install rollup-plugin-svgi --save-dev
yarn
yarn add rollup-plugin-svgi -D
Usage
// rollup.config.js
import svgi from 'rollup-plugin-svgi';
const config = {/* ... */};
export default {
entry: 'main.js',
plugins: [
svgi(config)
]
}
Configuration
The config
object passed to the plugin is composed of the following properties:
Property | Description | Default |
---|---|---|
options | The options object | undefined |
options.jsx | The JSX library to use e.g. "preact" or "react" | undefined |
options.factory | The JSX pragma or name of the function called at runtime for each node to e.g. preact.h or React.createElement | undefined |
options.default | Whether or not the options.factory is the default export of the provided options.jsx library.If false , the provided options.jsx will be a named export | true |
options.clean | The function used to clean up/ prepare the SVG for inlining | function |
exclude | Minimatch pattern(s) to exclude.More at rollupjs.org. | undefined |
include | Minimatch pattern(s) to include.More at rollupjs.org. | "**/*.svg" |
Basic setup
// main.js
import { h } from 'preact'; // OR import React from 'react';
import Logo from 'path/to/logo.svg';
export default () => (
<div class="App">
<div class="App-header">
<Logo class="App-logo" />
</div>
</div>
);
// rollup.config.js
import svgi from 'rollup-plugin-svgi';
export default {
entry: 'main.js',
// ...
plugins: [
svgi({
options: {
jsx: "preact", // Your chosen JSX library
},
}),
]
}
Advanced setup
/** EXAMPLE 1: Using a different JSX library */
// rollup.config.js
import svgi from 'rollup-plugin-svgi';
export default {
entry: 'main.js',
plugins: [
svgi({
options: {
jsx: "inferno-create-element",
factory: "createElement",
'default': false // import { createElement } from 'inferno-create-element';
},
}),
]
}
/** EXAMPLE 2: Using svgo as custom `options.clean` */
// rollup.config.js
import svgi from 'rollup-plugin-svgi';
export default {
entry: 'main.js',
plugins: [
svgi({
options: {
jsx: "react",
exclude: ['**/*.dev.svg', '**/*.max.svg'],
},
}),
]
}
0.2.0
5 years ago
0.2.0-dev.3
5 years ago
0.2.0-dev.2
5 years ago
0.2.0-dev.1
5 years ago
0.2.0-dev.0
5 years ago
0.1.2
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago