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 use local images

See original GitHub issue

Hello

In the sample I see how to use the Image component but how about images I have in my local repository?

  • deck.mdx
  • images/hero.jpg

This does not work

<Image
  src='./images/hero.jpg'
  style={{
    width: '100vw',
    height: '100vh',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center'
  }}>

## Background Image

</Image>

Variations I tried for src are

/images/hero.jpg
images/hero.jpg

All don’t show my image.

Many thanks.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

22reactions
therealparmeshcommented, Feb 16, 2020

Does this work for y’all?

// Photo ⬇️

import i from './image.jpg';

<img src={i} />

// Video ⬇️

import v from './video.mp4';

<video controls>
  <source src={v} />
</video>

// Audio ⬇️

import a from './audio.mp3';

<audio controls>
  <source src={a} />
</audio>

// Object ⬇️

import o from './object.pdf';

<object data={o} />
8reactions
karlito40commented, Feb 1, 2020

I had the same question. As a workaround i serve all my static files from another local server.

So basically you just do:

npm i concurrently --save-dev

and next replace your package.json scripts section with the following:

"scripts": {
    "start": "concurrently \"npm:mdx\" \"npm:static\"",
    "mdx": "mdx-deck deck.mdx",
    "static": "cd static && python -m SimpleHTTPServer 8081"
  }

You will now be able to access your static files from http://localhost:8081 as shown below:

---

<Image src="http://localhost:8081/word-art.png"/>

---
Read more comments on GitHub >

github_iconTop Results From Across the Web

docker - How can I use a local image as the base image with a ...
I just realised that I've been using FROM with indexed images all along. So I wonder: How can I use one of my...
Read more >
Two easy ways to use local Docker images in Minikube
First, we navigate to the app folder. Next, we build the Docker container via docker build -t pz/demo . , using the -t...
Read more >
How to Use Own Local Docker Images With Minikube - Medium
First, we need to set the environment variable with eval command eval $(minikube docker-env) · Build the docker image with the Minikube's Docker ......
Read more >
Using Local Docker Images With Minikube - Baeldung
Learn three different ways to run local Docker images in Minikube. ... We'll use Minikube to run the Kubernetes cluster.
Read more >
How to use a local registry - MicroK8s
The following documentation explains how to use MicroK8s with local images, or images fetched from public or private registries. A familiarity with building, ......
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