J
J
John Johnson2019-08-04 17:44:29
JavaScript
John Johnson, 2019-08-04 17:44:29

How to set up relative paths in webpack?

Hello . Please tell me, I raised the project through create react app and such a problem: I
inserted the video tag, specified the relative path to the video file in the src attribute, but it does not work. after some time found out that webpack changes the path
i.e.
the path import video from '../../img/video/mainstream.mp4'
it sees as Video /static/media/mainstream.bbae5fec.mp4
How to solve this problem ?
5d46ef49c414d837385087.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2019-08-04
@Rocknrolla99

after some time found that webpack changes the path
i.e.
the path import video from '../../img/video/mainstream.mp4'
he sees as Video /static/media/mainstream.bbae5fec.mp4

Everything is correct. The path changes the corresponding loader. If you look in the project folder, you can find the build directory there . The loader copies your video into it. You need to host the build folder with a static server.
Deployment
As for defining the path to the file in the tag attribute, with webpack this is done like this:
<video src={require('../../img/video/mainstream.mp4')} />

A
Andrey Suha, 2019-08-04
@andreysuha

I use aliases, a very handy thing. Like variables for paths

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question