Replace svg images with inline svg during grunt build process
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-img-to-inlinesvg --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-img-to-inlinesvg');
Plugin only replace content and does not care about optimalization of svg icons. You have to optimize svg before to inline them. Use SVGO plugin.
In your project's Gruntfile, add a section named img_to_inlinesvg
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
img_to_inlinesvg: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
});
Type: Number
Default value: 10
A number value that is used to limit svg file size. If file size will be bigger than this limit, image will be skipped and will not be inlined.
Type: String
Default value: ``
If you will use absolute path /path/to/image.svg
you can specify directory to replace /
to options.assetsDir
.
Type: String
Default value: img[inline]
CSS selector of images to process inline SVG insertion.
grunt.initConfig({
img_to_inlinesvg: {
options: {
svgFileLimit: 10,
assetsDir: "",
selector: "img[inline]"
},
files: {
'dest/index.html': ['src/index.html'],
},
},
});
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
(Nothing yet)