morlay / babel-plugin-transform-require-ignore

65 stars 13 forks source link

Error: ./shape.svg should not be assign to variable #6

Closed chipit24 closed 7 years ago

chipit24 commented 7 years ago

I have the following code inside one of my components:

const shape = require('./shape.svg');
...
<img src={shape}/>

I set my babelrc up to ignore svg files:

"env": {
    "node": {
      "plugins": [
        [
          "babel-plugin-transform-require-ignore",
          {
            "extensions": [".scss", ".css", ".svg", ".png"]
          }
        ]
      ]
    }
  }

However, I get an error, ./shape.svg should not be assign to variable. When I remove ".svg" from extensions, it gives me a syntax error inside shape.svg.

morlay commented 7 years ago

For svg file or png file which is required by webpack loader, prefer to use https://github.com/morlay/babel-plugin-webpack-loaders-inline-exports.