Can't get this plugin to work / Don't understand how to use it
See original GitHub issueWhat 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'
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top Results From Across the Web
WordPress Plugin Troubleshooting: What To Do When Your ...
Go to the Plugins page. · Click the Deactivate link associated with the plugin causing the issue. · Check your site. · If...
Read more >Here's a possible fix for when the plugin doesn't work
Obviously if/when the plugin is updated and this fix is not part of that update, the change will get lost. This could easily...
Read more >WordPress plugin not working? Check these 5 things - Yoast
When a plugin doesn't seem to work, this checklist will help you determine the possible cause. Follow these steps and find the solution!...
Read more >Why Can't I Add or Install Plugins in WordPress? - WPBeginner
We hope this article helped you learn why you can't add or install plugins in WordPress. You may also want to see our...
Read more >Why Can't I Install Plugins on WordPress? (Solved)
This article created by our team at wpDataTables will provide the answer to your question, why can't I install plugins on WordPress.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I worked out why this wasn’t working my specific case… basically don’t use the rails asset pipeline to load your SVGs, I had to move them into the same directory as my React app and use the relative URL.
yes, this approach relies on babel, and you’d want to avoid using the rails asset pipeline for svgs when using it.