How to handle image assets in React Library
See original GitHub issueI have scaffolded a React Library and a Next.js app using the generators. I am wanting to use a svg asset directly in a component but I’m unsure how to import/reference it. In CRA, I was able to do something like import { ReactComponent as MySVG } from 'path/to/my/file.svg'
Issue Analytics
- State:
- Created 4 years ago
- Comments:23 (17 by maintainers)
Top Results From Across the Web
Adding Images, Fonts, and Files - Create React App
Adding Images, Fonts, and Files. With webpack, using static assets like images and fonts works similarly to CSS.
Read more >Do I store Image assets in public or src in reactJS?
In react best practices we keep an assets folder inside the src which may contain top-level CSS, images, and font files.
Read more >How to display images from local assets/images folder when ...
In this article, we will see how we can load local images when using React. So let's get started. 1.When using Create React...
Read more >Managing assets for React project | Geek Culture - Medium
But the best approach is to segment the images according to their purpose together and if something common comes onto your place add...
Read more >Where to Store Images in React App | Upbeat Code
Storing Images in Source Directory · Serving Images as Static Assets · Storing Images on External Server.
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 see issue is closed but I feel like it side tracked to handling icons/SVGs. Still title is “How to handle image assets in React Library” and this is exactly what I have problem with.
When doing stuff like that:
Doesn’t matter the size, this image gets bundled inline to library dist code (works fine for app bundler). I get why this happens - we do not know what configuration will be used to bundle final app. Still I have to ask is there a better way? Library could inform that in order to use it one needs to use some assets bundling plugins etc.
If there is no other way, perhaps we could at least update docs: https://nx.dev/latest/react/guides/adding-assets-react to inform about different behaviour with libs.
This thread should be reopened as it’s handling a totally different scenario that bundling SVG in NX libs (NOT apps)