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.

Components doesn't ship with images properly

See original GitHub issue

Current Behavior

I have been trying to create a react component with images for the purpose of reusing them across different apps.

However, when I build the library and import the component, the component works fine except all the images are not referenced properly

I also tried running Storybook and I got the same issue.

Expected behavior

Build process should ship images properly

Suggested solution(s)

Additional context

  1. I run tsdx build on the prepare script in the package.json
  2. I tried using babel-plugin-file-loader, rollup-plugin-url and rollup-plugin-image but they didn’t work.

Your environment

Software Version(s)
TSDX 0.9.3
TypeScript 3.6.2
Browser Chrome Version 77.0.3865.120
npm/Yarn Yarn 1.19.1
Node 10.15.3
Operating System MacOS Mojave 10.14.6

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

5reactions
asyarbcommented, Apr 3, 2020

Sharing my config workaround to get images to work with tsdx.

// tsdx.config.js
const images = require('rollup-plugin-image-files')

module.exports = {
  rollup(config, options) {
    config.plugins = [
      images({ incude: ['**/*.png', '**/*.jpg'] }),
      ...config.plugins,
    ]

    return config
  },
}

It seems like your rollup plugin to handle images needs to come before tsdx’s plugins. (I’m guessing before rollup-plugin-typescript2?).


I tried to get this working with @rollup/plugin-url, but couldn’t figure it out. If anyone is interested, my config with @rollup/plugin-url can be seen below.

Maintainer edit: updated to reflect v0.13.0+

const url = require('@rollup/plugin-url')

module.exports = {
  rollup(config, options) {
    config.plugins = [
      // Force the `url` plugin to emit files.
      url({ limit: 0, incude: ['**/*.png', '**/*.jpg'] }),
      ...config.plugins,
    ]

    return config
  },
}

The main problem seems to be that @rollup/plugin-url will generate a plain string instead of leveraging a require when you try to use an asset, which wont signal to a library consumer’s bundler to properly generate the path for their project. (can be seen in action with Parcel in the example/ directory)

0reactions
agilgur5commented, Mar 9, 2020

Going to close the out since a solution was found. See https://github.com/jaredpalmer/tsdx/issues/379#issuecomment-568239477 for the summary from here.

Import order seems to affect this specific plugin. I’m not really sure why @rollup/plugin-url doesn’t work

Read more comments on GitHub >

github_iconTop Results From Across the Web

img not showing up in styled components reactjs
Image path is correct. But image is not showing up. HTML img is showing up in the DOM, but not include src attribute....
Read more >
Image not appearing on Lightning Component [duplicate]
In my below lightning component , I am trying to display an image using background image tag. <div class="imageview" style="{!'background-image: ...
Read more >
Different Parts Of A Ship Explained - Marine Insight
Three necessary parts of the ship are the hull (the main body of the vessel), navigation bridge (helps in directing the ship in...
Read more >
12 Important Image SEO Tips You Need To Know
Discover which factors are essential for optimizing images to improve your content and help it rank higher in search.
Read more >
How to properly pack and ship a PC! - YouTube
Today I prepare Kiapiaa's PC for shipment, but there are some important steps to take to ensure that it arrives safe and sound!...
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