question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to handle image assets in React Library

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:23 (17 by maintainers)

github_iconTop GitHub Comments

12reactions
Bielik20commented, Nov 2, 2020

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:

import image from './sample-image.jpg';

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.

6reactions
owen26commented, Sep 30, 2021

This thread should be reopened as it’s handling a totally different scenario that bundling SVG in NX libs (NOT apps)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found