Answer the question
In order to leave comments, you need to log in
How to get local images outside of the project?
Hello!
Directory (conditionally):
-папка
|-проект
|-dist
|-public
|-src
|-main.js
|-webpack.config.js
|-картинки
|-папка_с 1м_набором
|-папка_с_2м_набором
|-папка_с_3м_набором
|-index.js
картинки/index.js
картинки/index.js
code:export default [{
url: "папка_с_1м_набором/картинка1.png",
},
{
url: "папка_с_2м_набором/картинка1.png",
},
...]
require.context("../../папка_с_1м_набором/картинка1.png", true, /\.png$/)
Answer the question
In order to leave comments, you need to log in
These pictures are not on the server, because no one puts them there. The server ( webpack devserver ) does not work from a local folder, but from a structured folder as described in the build result config. Do a build and look in the dist folder: this is exactly what the file structure on the server looks like.
You can put this image folder there using the copy-webpack-plugin . If this folder is placed on the server manually and in prod. dist you don't need it - you can include this plugin only for develpment.
Alternatively you can set up devserver (using before / after) so that it simply gives the files from this folder upon the appropriate request (reading their contents manually using node fs tools ).
The main thing is not to forget then to put this folder on the server with your hands.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question