export-svg-loader
svg-to-img.
A webpack loader to convert SVGs to images built withGetting Started
Installation
To use export-svg-loader in your project, run:
npm install export-svg-loader -D
Note This project uses await/async then node v7.6.0 or greater it's required to work.
Usage
The loader may be configured to export a single or multiple extensions with varying dimensions.
- type - (Optional). Extension that svg file is going to be exported. Default to
png
. - fileName - (Optional). A template string for the output file name. Defaults to [svg-file-name].
[extension]
. Also you can send as array to export multiple images. - sizes - (Optional). Used to export multiple images for a single input SVG. Holds an array of sizes. Size entries may be formatted like [height]xwidth. Also can send as string for one unique export or just number for square dimensions.
- publicPath: (Optional). Places where the image is going to be exported. It's necessary to set as relative path to output.
Example - converting a svg
to png
:
moduleexports = //... module: rules: test: /\.svg$/ use: 'export-svg-loader' ;
Example - converting a svg
to ico
and saving the image as example.jpeg:
moduleexports = //... module: rules: test: /\.svg$/ use: loader: 'export-svg-loader' options: type: 'ico' ;
Example - converting a svg
to jpeg
and saving the image as example.jpeg:
moduleexports = //... module: rules: test: /\.svg$/ use: loader: 'export-svg-loader' options: type: 'jpeg' fileName: 'example' ;
Example - resizing a svg
proportionally and converting it to webp
in dist/images
folder :
moduleexports = //... module: rules: test: /\.svg$/ use: loader: 'export-svg-loader' options: type: 'webp' publicPath: 'dist/images' ;
Example - converting a svg
to png
with width 40
and height 30
:
moduleexports = //... module: rules: test: /\.svg$/ use: loader: 'export-svg-loader' options: sizes: '40x30' ;
Example - converting a svg
to png
with width 40
and height 40
as number
:
moduleexports = //... module: rules: test: /\.svg$/ use: loader: 'export-svg-loader' options: sizes: 40 ;
Example - converting a svg
to png
with the follow sizes: 30x30
, 40x40
, 70x90
:
moduleexports = //... module: rules: test: /\.svg$/ use: loader: 'export-svg-loader' options: sizes: '30x30' '40x40' '70x90' ;
Note - If we don't specify an array of custom name it will generate images with the width dimension. Example: icon30.png
, icon40.png
and icon70.png
Example - converting a svg
to png
with the follow sizes: 30x30
, 40x40
, 70x90
and an array of custom names:
moduleexports = //... module: rules: test: /\.svg$/ use: loader: 'export-svg-loader' options: sizes: '30x30' '40x40' '70x90' fileName: 'image30x30' 'image40x40' 'image70x90' ;
Built with
- node.js - Cross-platform JavaScript run-time environment for executing JavaScript code server-side.
- Jest - Delightful JavaScript Testing.
Contributing
When contributing to this project, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
Update the README.md with details of changes to the library.
Execute npm run test
and update the tests if needed.
License
This project is licensed under the MIT License - see the LICENSE file for details.