Skip to content

Instantly share code, notes, and snippets.

@avillegasn avillegasn/my-component.js
Last active Jun 28, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.