0.2.0 • Published 5 years ago

rollup-plugin-svgi v0.2.0

Weekly downloads
200
License
MIT
Repository
github
Last release
5 years ago

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:

PropertyDescriptionDefault
optionsThe options objectundefined
options.jsxThe JSX library to use e.g. "preact" or "react"undefined
options.factoryThe JSX pragma or name of the function called at runtime for each node to e.g. preact.h or React.createElementundefined
options.defaultWhether 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 exporttrue
options.cleanThe function used to clean up/ prepare the SVG for inliningfunction
excludeMinimatch pattern(s) to exclude.More at rollupjs.org.undefined
includeMinimatch 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