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 load images and other static assets?

See original GitHub issue

Hello,

What is the best way to load images and other assets that will work for both client & server? I could add url-loader and file-loader to webpack config but it will not work on the server.

Are there other options?

Thanks, Ran.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

9reactions
jaredpalmercommented, Jun 2, 2016

@justingreenberg babel-register can’t handle the image file types, a workaround is to modify server:

require('babel-register');
if (process.env.NODE_ENV == 'development') {
  require.extensions['.png'] = function () {};
  require.extensions['.jpg'] = function () {};
  require.extensions['.jpeg'] = function () {};
  require.extensions['.woff'] = function () {};
  require.extensions['.woff2'] = function () {};
  require.extensions['.ico'] = function () {};
  require.extensions['.svg'] = function () {};
}
require('./server');
5reactions
justingreenbergcommented, Jun 2, 2016

@jaredpalmer hey man, thanks for the awesome kit 😃 i’m sorry to drudge this back up, but may i ask how you are handling SSR images/statics like fonts in your projects? for example, how are you approaching:

// logo-component.js
import LogoImage from './logo.png' // colocated image in component folder

export default ({ linkUrl }) =>
  <a href={linkUrl}>
    <img src={LogoImage} alt="Logo" /> 
  </a>

i’ve been using webpack-isomorphic-tools to handle above cases, which works but the ergonomics and setup feels very brittle and hacky… i’m about to start another project, it would be really great to hear your thoughts and approach—it feels like assets.json could be used for statics as well

thanks again jared, any direction, boilerplate or webpack config you could provide would be greatly appreciated, and i’d be happy to submit a PR if it’s something you want to add to starter

i suspect i’m probably overlooking a super simple solution… thanks again!! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to manage static files (e.g. images, JavaScript, CSS)
Store your static files in a folder called static in your app. For example my_app/static/my_app/example. jpg .
Read more >
Images, fonts, and assets - Storybook - JS.ORG
We recommend serving static files via Storybook to ensure that your components always have the assets they need to load. We recommend this...
Read more >
Static Assets - Docusaurus
Static assets are the non-code files that are directly copied to the build output. They include images, stylesheets, favicons, fonts, etc. By ...
Read more >
Using the Static Folder - Gatsby
In general, every website needs assets: images, stylesheets, scripts, etc. ... Every file you put into that folder will be copied into the...
Read more >
Basic Features: Static File Serving - Next.js
Next.js can serve static files, like images, under a folder called public in the root directory. Files inside public can then be referenced...
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