Detalhes do pacote

svg-inline-loader

sairion888.8kMIT0.8.2

Cleans up and inlines your SVG files into Webpack module.

svg, webpack, react, loader

readme (leia-me)

npm deps test coverage chat

SVG Inline Loader for Webpack

This Webpack loader inlines SVG as module. If you use Adobe suite or Sketch to export SVGs, you will get auto-generated, unneeded crusts. This loader removes it for you, too.

Install

npm install svg-inline-loader --save-dev

Configuration

Simply add configuration object to module.loaders like this.

    {
        test: /\.svg$/,
        loader: 'svg-inline-loader'
    }

warning: You should configure this loader only once via module.loaders or require('!...'). See #15 for detail.

Query Options

removeTags: boolean

Removes specified tags and its children. You can specify tags by setting removingTags query array.

default: removeTags: false

removingTags: [...string]

warning: this won't work unless you specify removeTags: true

default: removingTags: ['title', 'desc', 'defs', 'style']

warnTags: [...string]

warns about tags, ex: ['desc', 'defs', 'style']

default: warnTags: []

removeSVGTagAttrs: boolean

Removes width and height attributes from <svg />.

default: removeSVGTagAttrs: true

removingTagAttrs: [...string]

Removes attributes from inside the <svg />.

default: removingTagAttrs: []

warnTagAttrs: [...string]

Warns to console about attributes from inside the <svg />.

default: warnTagAttrs: []

classPrefix: boolean || string

Adds a prefix to class names to avoid collision across svg files.

default: classPrefix: false

idPrefix: boolean || string

Adds a prefix to ids to avoid collision across svg files.

default: idPrefix: false

Example Usage

// Using default hashed prefix (__[hash:base64:7]__)
var logoTwo = require('svg-inline-loader?classPrefix!./logo_two.svg');

// Using custom string
var logoOne = require('svg-inline-loader?classPrefix=my-prefix-!./logo_one.svg');

// Using custom string and hash
var logoThree = require('svg-inline-loader?classPrefix=__prefix-[sha512:hash:hex:5]__!./logo_three.svg');

See loader-utils for hash options.

Preferred usage is via a module.loaders:

    {
        test: /\.svg$/,
        loader: 'svg-inline-loader?classPrefix'
    }

Maintainers


Juho Vepsäläinen

Joshua Wiens

Kees Kluskens

Sean Larkin

changelog (log de mudanças)

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.8.2 (2020-02-17)

0.8.1 (2020-02-07)

0.8.0 (2017-07-16)

Bug Fixes

  • add missing idPrefix as default value to config, close #36 (ba7738d)
  • corrupted css properties in style tag (2d28c42)
  • don't transform webpack2 query objects (9373e3e)
  • multiple classes in class string fix (2024e06)

Features

  • warnTags and warnTagAttrs (ada00d7)

0.6.1

  • Fixed a bug when using removingTagAttrs

0.6.0

  • Added classPrefix option (by @kinetifex)

0.5.0

  • Added removingTagAttrs option (by @iernie)

0.4.0

0.3.0

  • Isolate transfomration functions and make tag removal optional, add README
  • Added React svg icon tag

0.2.3

  • Tag removal is fixed (<defs />, <style />, <title />, ...) and test added

0.2.2

  • Added unittest

0.2.1

  • Regex expanding self-closing tags added due to simple-html-tokenizer's behavior (by @rondonjon)
  • Added README and CHANGELOG

0.2.0

  • Fixed Non-<svg> elements' width and height attributes gets removed
  • Uses simple-html-tokenizer to tokenize html tags

0.1.0

  • Initial implementation