Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: svg/svgo-loader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 20006d2e572991162ca93847e72179c0bdfe161f
Choose a base ref
...
head repository: svg/svgo-loader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c15d6911479f1ab7eebfbe5141f2155ff531e8c2
Choose a head ref
Loading
149 changes: 88 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,95 +6,122 @@
$ npm install svgo-loader --save-dev
```

... or with Yarn

```
$ yarn add svgo-loader -D
```

## Usage

[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)

Svgo-loader just passes config
to the [svgo](https://github.com/svg/svgo) library.

### Webpack 2

``` javascript
{
test: /\.svg$/,
use: [
{
loader: 'file-loader'
},
{
loader: 'svgo-loader',
options: {
plugins: [
{removeTitle: true},
{convertColors: {shorthex: false}},
{convertPathData: false}
[Documentation: Using loaders](https://webpack.js.org/concepts/loaders/#using-loaders)

```js
module.exports = {
...,
module: {
rules: [
{
test: /\.svg$/,
use: [
{
loader: 'file-loader'
},
{
loader: 'svgo-loader',
}
]
}
}
]
]
}
}
```

### Webpack 1

There is two ways of loading svgo configuration.
You can pass it as a JSON string after loader name, like this:

``` javascript
// webpack.config.js
By default svgo-loader uses config from `svgo.config.js` similar to svgo cli.
See [how to configure svgo](https://github.com/svg/svgo#configuration).

var svgoConfig = JSON.stringify({
plugins: [
{removeTitle: true},
{convertColors: {shorthex: false}},
{convertPathData: false}
]
});
Specify configFile option to load custom config module:

```js
module.exports = {
...
...,
module: {
loaders: [
rules: [
{
test: /.*\.svg$/,
loaders: [
'file-loader',
'svgo-loader?' + svgoConfig
test: /\.svg$/,
use: [
{
loader: 'file-loader'
},
{
loader: 'svgo-loader',
options: {
configFile: './scripts/svgo.config.js'
}
}
]
}
]
}
}
```

Or you can save svgo config in your main webpack config object,
and then specify name of the property in the loader query string.
or to disable loading config:

However, this option will not work in Webpack 2.<br>This is only shown here in the documentation for backwards compatibility.
```js
module.exports = {
...,
module: {
rules: [
{
test: /\.svg$/,
use: [
{
loader: 'file-loader'
},
{
loader: 'svgo-loader',
options: {
configFile: false
}
}
]
}
]
}
}
```

``` javascript
// webpack.config.js
You can also specify options which override loaded from config

```js
module.exports = {
...
...,
module: {
loaders: [
rules: [
{
test: /.*\.svg$/,
loaders: [
'file-loader',
'svgo-loader?useConfig=svgoConfig1'
test: /\.svg$/,
use: [
{
loader: 'file-loader'
},
{
loader: 'svgo-loader',
options: {
multipass: true,
js2svg: {
indent: 2,
pretty: true,
}
}
}
]
}
]
},
svgoConfig1: {
plugins: [
{removeTitle: true},
{convertColors: {shorthex: false}},
{convertPathData: false}
]
}
}
```

## License and Copyright

This software is released under the terms of the [MIT license](https://github.com/svg/svgo-loader/blob/master/LICENSE).
File renamed without changes
File renamed without changes.
24 changes: 24 additions & 0 deletions example/basic/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
mode: "production",
context: __dirname,
entry: "./entry",
output: {
path: __dirname + "/dist",
filename: "bundle.js"
},
module: {
rules: [
{
test: /\.svg$/,
use: [
{
loader: 'file-loader'
},
{
loader: '../../index.js',
}
]
}
]
}
}
Loading