Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SVGR support to wp-scripts #18243

Merged
merged 6 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Should there be any situation where you want to provide your own webpack config,

To extend the provided webpack config, or replace subsections within the provided webpack config, you can provide your own `webpack.config.js` file, `require` the provided `webpack.config.js` file, and use the [`spread` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) to import all of or part of the provided configuration.

In the example below, a `webpack.config.js` file is added to the root folder extending the provided webpack config to include [`@svgr/webpack`](https://www.npmjs.com/package/@svgr/webpack) and [`url-loader`](https://github.com/webpack-contrib/url-loader):
In the example below, a `webpack.config.js` file is added to the root folder extending the provided webpack config to include [`css-loader`](https://github.com/webpack-contrib/css-loader) and [`style-loader`](https://github.com/webpack-contrib/style-loader):

```javascript
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
Expand All @@ -392,12 +392,13 @@ module.exports = {
rules: [
...defaultConfig.module.rules,
{
test: /\.svg$/,
use: ["@svgr/webpack", "url-loader"]
test: /\.css$/,
use: ["css-loader", "style-loader"],
}
]
}
};
```

If you follow this approach, please, be aware that future versions of this package may change what webpack and Babel plugins we bundle, default configs, etc. Should those changes be necessary, they will be registered in the [package’s CHANGELOG](https://github.com/WordPress/gutenberg/blob/master/packages/scripts/CHANGELOG.md), so make sure to read it before upgrading.
<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
4 changes: 4 additions & 0 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const config = {
},
],
},
{
test: /\.svg$/,
use: [ '@svgr/webpack', 'url-loader' ],
},
],
},
plugins: [
Expand Down
2 changes: 2 additions & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"wp-scripts": "./bin/wp-scripts.js"
},
"dependencies": {
"@svgr/webpack": "^4.3.3",
"@wordpress/babel-preset-default": "file:../babel-preset-default",
"@wordpress/dependency-extraction-webpack-plugin": "file:../dependency-extraction-webpack-plugin",
"@wordpress/eslint-plugin": "file:../eslint-plugin",
Expand Down Expand Up @@ -60,6 +61,7 @@
"stylelint": "^9.10.1",
"stylelint-config-wordpress": "^13.1.0",
"thread-loader": "^2.1.2",
"url-loader": "^3.0.0",
mkaz marked this conversation as resolved.
Show resolved Hide resolved
"webpack": "^4.41.0",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^3.1.2",
Expand Down