Skip to content

Instantly share code, notes, and snippets.

@avillegasn
Last active June 28, 2019 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avillegasn/e8f85c9362945219d102e0b9d2c6548e to your computer and use it in GitHub Desktop.
Save avillegasn/e8f85c9362945219d102e0b9d2c6548e to your computer and use it in GitHub Desktop.
Extending @wordpress/scripts to load SVG files inside JSX files.
import {
Component,
Fragment,
} from '@wordpress/element';
import Icon from './icon.svg';
class MyComponent extends Component {
render() {
return (
<Fragment>
<p>Let's print an icon...</p>
<Icon />
</Fragment>
);
}
}
export default MyComponent;
const defaultConfig = require("./node_modules/@wordpress/scripts/config/webpack.config");
module.exports = {
...defaultConfig,
module: {
...defaultConfig.module,
rules: [
...defaultConfig.module.rules,
{
test: /\.svg$/,
issuer: /\.js$/,
use: [
{
loader: 'svg-react-loader',
}
],
},
],
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment