Skip to content

Commit

Permalink
Merge pull request #5 from pixel-point/2.0.0
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
SilencerWeb authored Dec 3, 2021
2 parents 20cc5d2 + add1c57 commit 047446f
Show file tree
Hide file tree
Showing 4 changed files with 33,119 additions and 345 deletions.
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ plugins: [
svgoConfig: {
plugins: [
{
removeViewBox: false,
name: "preset-default",
params: {
overrides: [{ name: "removeViewBox", active: false }],
},
},
"prefixIds",
],
},
},
Expand All @@ -90,11 +94,7 @@ plugins: [
{
test: /\.svg$/,
svgoConfig: {
plugins: [
{
removeViewBox: false,
},
],
plugins: [{ name: "removeViewBox", active: false }],
},
},
],
Expand All @@ -111,7 +111,7 @@ You can declare various rules based on loader that should be used under `inlineS

`svgo` - disables SVGO if set in `false`

### SVGO disabled example:
### SVGO disabled example

```js
plugins: [
Expand Down Expand Up @@ -140,15 +140,11 @@ urlSvgOptions: [
{
test: /\.svg$/,
svgoConfig: {
plugins: [
{
removeViewBox: false,
},
],
plugins: [{ name: "removeViewBox", active: false }],
},
urlLoaderOptions: {
limit: 512,
},
},
],
];
```
30 changes: 16 additions & 14 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defaultUrlSvgOptions = [
];

exports.onCreateWebpackConfig = (
{ getConfig, actions, loaders, stage },
{ getConfig, actions, stage },
{
inlineSvgOptions = defaultInlineSvgOptions,
urlSvgOptions = defaultUrlSvgOptions,
Expand All @@ -28,7 +28,7 @@ exports.onCreateWebpackConfig = (
const { replaceWebpackConfig, setWebpackConfig } = actions;
const existingConfig = getConfig();

// Run only for the specificified build stages
// Run only for the specificified build stages
if (
["develop", "develop-html", "build-html", "build-javascript"].includes(
stage
Expand Down Expand Up @@ -56,19 +56,21 @@ exports.onCreateWebpackConfig = (
});

// Prepare svg rules for inline usage
const inlineSvgRules = inlineSvgOptions.map((option) => ({
test: option.test,
use: [
{
loader: require.resolve("@svgr/webpack"),
options: {
svgo: option.svgo === undefined ? true : option.svgo,
svgoConfig: option.svgoConfig,
const inlineSvgRules = inlineSvgOptions.map(
({ test, svgo, ...otherOptions }) => ({
test: test,
use: [
{
loader: require.resolve("@svgr/webpack"),
options: {
svgo: svgo === undefined ? true : svgo,
...otherOptions,
},
},
},
],
issuer: /\.(js|jsx|ts|tsx)$/,
}));
],
issuer: /\.(js|jsx|ts|tsx)$/,
})
);

const urlSvgRules = [];
// Prepare svg rules for url loader usage with SVGO
Expand Down
Loading

0 comments on commit 047446f

Please sign in to comment.