Comments (5)
Just hit by the same issue today, I searched a bit how to solve this.
I am only using @rescripts/rescript-use-babel-config
with a custom .babelrc
file.
To solve the problem, I had to add this plugin in my .babelrc
config:
"plugins": [
["babel-plugin-named-asset-import", {
"loaderMap": {
"svg": {
"ReactComponent": "@svgr/webpack?-svgo,+ref![path]"
}
}
}]
]
This sould probably be added somewhere in the use-babel-config
documentation.
And note also that the correct syntax to load svg is
import { ReactComponent as Logo } from './logo.svg';
class App extends Component {
render() {
return (
<Logo width="400px" height="400px" />
);
}
}
from rescripts.
Hi @hckhanh –– I don't believe this to be an issue with Rescripts. Still, I'll try to offer some support.
This kind of import seems a little strange:
import { ReactComponent as DeleteIcon } from './delete.svg';
There's no exported "ReactComponent" from an svg file. Maybe replace with the following:
import DeleteIcon from './delete.svg';
I hope this is helpful (there's a change you'll need to include an SVG loader such as airbnb's). Although I'm pretty sure SVG imports are supported as of CRA 2.0+. Keep me posted :)
from rescripts.
@harrysolovay I think this is a new feature is supported by CRA. When I do by this way, it will convert data in svg file to a React component like this:
You're right, it's strange when I use it in the first time but I think this one is really good, like the same way Github inserts their svg file.
It runs perfectly when use react-scripts
. You can try react-scripts start
to test it 👍
Additionally, I can add event such as onClick as a native component like div
from rescripts.
@hckhanh can you send me a link to the example so I can debug?
from rescripts.
@hckhanh hopefully you managed to find the problem. Gonna close this issue. Feel free to reopen if necessary.
from rescripts.
Related Issues (20)
- Compatibility with custom react-scripts forks HOT 1
- Show error output for rescript config errors HOT 3
- Global configuration not taken into account HOT 1
- Dev server hangs when trying to add another entry point HOT 4
- react-dev-utils need to be updated HOT 1
- .babelrc.js export function does not work HOT 3
- Adding ".babelrc" breaks typescript support in react HOT 1
- Allow react-scripts v4 without npm warning
- Typescript update to 4.X? HOT 1
- Install the last version of react-dev-utils to fix a vulnerability HOT 2
- No matching version for @rescripts/rescript-use-eslint-config dependency in @rescripts/rescript-env HOT 7
- How do I extend the jest config? HOT 1
- Setting a static name for the files generated by build HOT 2
- Webpack config HOT 4
- how to config webpack devServer' before(app) HOT 6
- PostCSS config not working HOT 1
- [Question] Multiple entry points + shared/common chunks howto example for noobs HOT 1
- Is there any way how to easily change paths? HOT 3
- How to add a devserver before or after hook? HOT 1
- How to get React Fast Refresh to work HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rescripts.