New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@zumwald/html-webpack-inline-svg-plugin

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zumwald/html-webpack-inline-svg-plugin

Embed svg inline when using the html webpack plugin

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by1000%
Maintainers
1
Weekly downloads
 
Created
Source

Inline SVG extension for the HTML Webpack Plugin

npm version Build status

Allows you to inline SVGs that are parsed by html-webpack-plugin.

Now you can easily add inline SVGs to your output html. Combined with techniques such as: Icon System with SVG Sprites you have a simple way of ensuring your svg referenced icons are always visible.

The plugin relies on svgo to optimise SVGs. You can configure it's settings, check below for more details.

Installation

Install the plugin with npm:

$ npm install --save-dev html-webpack-inline-svg-plugin

or yarn:

$ yarn add html-webpack-inline-svg-plugin --dev

Usage

Require the plugin in your webpack config:

const HtmlWebpackInlineSVGPlugin = require('html-webpack-inline-svg-plugin');

Add the plugin to your webpack config as follows:

plugins: [
    new HtmlWebpackPlugin(),
    new HtmlWebpackInlineSVGPlugin()
]

Add img tags with inline attribute and .svg file as src to your template/s that the html-webpack-plugin is processing (the default is index.html).

<!-- Works: below img tag will be removed and replaced by the content of the svg in its src -->
<img inline src="static/icons.svg">

<!-- Ignored: this img will not be touched as it has no inline attribute -->
<img src="static/foo.svg">

<!-- Broken: this plugin will ignore this src as it is not an svg -->
<img inline src="static/i-will-be-ignored.png">

Getting to your SVGs

References to your *.svg files within the img tags src should be relative to your project root, this is usually the directory your package.json file sits in:

my-project
-- package.json
-- <node_modules>
-- <static>
---- icons.svg
---- foo.svg
---- ...

With the above structure inlining icons.svg would look like: <img inline src="static/icons.svg">

Config

To configure SVGO (module used to optimise your SVGs), add an svgoConfig object to your html-webpack-plugin config:

plugins: [
    new HtmlWebpackPlugin({
        svgoConfig: {
            removeTitle: false,
            removeViewBox: true,
        },
    }),
    new HtmlWebpackInlineSVGPlugin()
]

For a full list of the SVGO config (default) params we are using check out: svgo-config.js. The config you set is merged with our defaults, it does not replace it.

Known Issues

  • none currently

Keywords

FAQs

Package last updated on 21 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc