airbnb / airbnb/babel-plugin-inline-react-svg

Can't get this plugin to work / Don't understand how to use it

Open
#67 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
474
Forks
90
PR merge metrics
No merged PRs in 30d

Description

**What we had before:**
- react-svg-loader (400KB(!) minified + gzipped)
**webpack.config.js:**

test: /\.svg$/,
use: [
'babel-loader',
{
loader: 'react-svg-loader',
options: {
svgo: {
plugins: [
{ removeTitle: false },
],
},
},
},
],

In a .jsx file we import svg's like:

import Logo from 'assets/logo.svg'; // get's it from root even though component is in subfolder
import Logo from '../assets/logo.svg'; // I tried this as well with this module (correct relative)

**What I did to replace `react-svg-loader` with `babel-plugin-inline-react-svg`:**
**webpack.config.js:**

test: /\.svg$/,
use: [
'babel-loader',
],

.babelrc

- "@babel/plugin-proposal-function-bind"
+ "@babel/plugin-proposal-function-bind",
+ [
+ "inline-react-svg",
+ {
+ "svgo": {
+ "plugins": [
+ {
+ "removeAttrs": { "attrs": "(data-name)" }
+ },
+ {
+ "cleanupIDs": true
+ },
+ { "removeTitle": false }
+ ]
+ }
+ }
+ ]

**The result?:** lots of these...:

Module build failed: Error: Cannot find module 'assets/logo.svg'

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with webpack.config.js and .babelrc, then trace the imports of assets/logo.svg and ../assets/logo.svg alongside the reported module-resolution error. Reproduce the build and determine whether the plugin configuration handles these imports; done means SVG imports compile without the "Cannot find module" failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript, react, webpack
Domain
build-system, frontend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.