JavaScript for WordPress Forums Gutenberg Development Plugin path in index.js file Reply To: Plugin path in index.js file

#60716
ldecoker
Participant

Thx Zac.

Hereunder what I have done to solve my issue (not sure this is the best solution but it works):

npm i react-svg-core --save-dev
npm i react-svg-loader --save-dev

Then in webpack.config.js (in module.exports):

externals: {
		react: {
			root: 'React',
			commonjs: 'react',
			commonjs2: 'react',
			amd: 'react'
		}
	},

and in rules:

{
				test: /\.svg$/,
				use: [
					{
						loader: "babel-loader"
					},
					{
						loader: "react-svg-loader",
						options: {
							jsx: true // true outputs JSX tags
						}
					}
				]
			}

Finally in index.js :
import ArrowBottom from '../../assets/images/arrow-bottom.svg';

and where you want to add your icon:
<ArrowBottom />

Do not hesitate to comment 🙂

Have a nice day!