Last active
June 28, 2019 07:55
-
-
Save avillegasn/e8f85c9362945219d102e0b9d2c6548e to your computer and use it in GitHub Desktop.
Extending @wordpress/scripts to load SVG files inside JSX files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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