Git Product home page Git Product logo

rollup-plugin-vue-inline-svg's Introduction

rollup-plugin-vue-inline-svg

Unit tests

A simple plugin to import svg files as vue components. This is intended to be used with rollup-plugin-vue and is based on vue-svg-loader.

installation

npm install --save-dev rollup-plugin-vue-inline-svg

usage

rollup.config.js

import svg from 'rollup-plugin-vue-inline-svg';
import vue from 'rollup-plugin-vue'; // optional

export default {
  // ...
  plugins: [
    svg(config)
    vue(), // optional
  ]
}

config

By default this plugin will attempt to transform all files that end with the extension .svg. You can be more explicit by passing include and exclude options.

// `include` and `exclude` can each be a minimatch
// pattern, or an array of minimatch patterns, relative to process.cwd()
{
  include: string or array of minimatch,
  exclude: string or array,
  svgoConfig: svgo config object,
}

See SVGO for configuration options that it accepts.

Import svgs from node_modules

The plugin is able to import svg files from node_modules packages:

import AlertSvg from 'octicons/build/svg/alert.svg'

The only important thing to remember is that the rollup build process needs to be started from the project root directory (e.g. via npm scripts). This is because the plugin will search the node_modules directory, via the process.cwd() node method, from where the process has started.

rollup-plugin-vue-inline-svg's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rollup-plugin-vue-inline-svg's Issues

Does not generate source maps.

Currently this plugin does not return a source map. This throws a warning at the moment.

Warning: Sourcemap is likely to be incorrect: a plugin ('vue-inline-svg') was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help
https://github.com/rollup/rollup/wiki/Troubleshooting#sourcemap-is-likely-to-be-incorrect

It should be easy to adopt the solution that rollup-plugin-prettier uses here - https://github.com/mjeanroy/rollup-plugin-prettier/blob/master/src/index.js#L88-L121

SVGO Plugin Options

Need to change SVGO Plugin options in configuration

Currently this plugin removes ids from imported svg's

(node:110330) UnhandledPromiseRejectionWarning: Error in parsing SVG: Non-whitespace before first tag

import svg from 'rollup-plugin-vue-inline-svg';

....

plugins: [
css(),
image({exclude: '*.svg'}),
svg(),
....

(node:110330) UnhandledPromiseRejectionWarning: Error in parsing SVG: Non-whitespace before first tag. Line: 0 Column: 1 Char: v (node:110330) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:110330) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. (node:110330) UnhandledPromiseRejectionWarning: Error in parsing SVG: Non-whitespace before first tag.

it looks like a conflict with @rollup/plugin-image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.