react-native-svg-web icon indicating copy to clipboard operation
react-native-svg-web copied to clipboard

Does react-native-svg work for the web?

Open kopax opened this issue 5 years ago • 3 comments

I have just opened those issues:

  • https://github.com/expo/expo/issues/6660
  • https://github.com/react-native-community/react-native-svg/issues/1235

It seems that react-native-svg is already for the web, but it does not work for me.

Every component imported in the web are just path and not react component.

Do I need this plugin ? If yes, how do I include it in expo ?

kopax avatar Jan 02 '20 20:01 kopax

If you are using webpack you can try this solution

https://github.com/react-native-svg/react-native-svg/issues/1478

KEMBL avatar Oct 17 '20 07:10 KEMBL

Hi @KEMBL! Thanks for your webpack solution. My webpack config is like this and I do alias like below. Now I'm a bit confused about how should I configure my webpack now. Could you please help me solve it

module.exports = function override(config, env) {
  // allow importing from outside of src folder
  config.resolve.plugins = config.resolve.plugins.filter(
    plugin => plugin.constructor.name !== 'ModuleScopePlugin'
  )
  /** alias-parrt **/
  config.resolve.alias['react-native-linear-gradient'] = 'react-native-web-linear-gradient'
  /** alias-parrt **/
  config.module.rules[0].include = appIncludes
  config.module.rules[1] = null
  config.module.rules[2].oneOf[1].include = appIncludes
  config.module.rules[2].oneOf[1].options.plugins = [
    require.resolve('babel-plugin-react-native-web'),
  ].concat(config.module.rules[2].oneOf[1].options.plugins)
  config.module.rules = config.module.rules.filter(Boolean)
  config.plugins.push(
    new webpack.DefinePlugin({ __DEV__: env !== 'production' })
  )

  return config
}

MohammadAzimi avatar Feb 03 '21 14:02 MohammadAzimi

I fixed it in this way as you said

  config.resolve.alias['react-native-svg'] = aliasPathJoin(['react-native-svg', 'lib', 'module', 'ReactNativeSVG.web.js'])

the problem in my svgs was the style attribute which I removed and everything works fine

MohammadAzimi avatar Feb 07 '21 11:02 MohammadAzimi