K
K
kirillleogky2020-01-08 12:25:32
JavaScript
kirillleogky, 2020-01-08 12:25:32

What is the correct path for images?

I have the following structure:
5e15a045ace08797459024.png
My original html is dist/landing/index.html:

<div class="header_block-logo">
                <div class="header_block-logo_text">Simple</div>
                <img src="../../src/img/logo_piskel.png" alt="Logo Piskel" class="header_block-logo_icon">
            </div>

webpack config:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: {
    app: './src/screens/app/index.js',
    landing: './src/screens/landing/index.js'
  },
  mode: 'development',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: "[name]/main.js"
  },
  module: {
  rules: [
    {
      test: /\.js$/,
      enforce: 'pre',
      exclude: /node_modules/,
      loader: 'eslint-loader',
    },
    {
      test: /\.scss$/,
      use: [{
          loader: "style-loader"
      }, {
          loader: "css-loader"
      }, {
          loader: "sass-loader",
      }]
    },
    {
      test: /\.(jpg|png|svg|ttf|woff|eot)$/,
      loader: 'url-loader',
      options: {
       name: 'img/[name].[ext]',
      },
    }
  ],
 },
  plugins: [
   new HtmlWebpackPlugin({
     inject: true,
     chunks: ['app'],
     template: 'src/screens/app/app.html',
     filename: 'app/index.html'
   }),
   new HtmlWebpackPlugin({
     inject: true,
     chunks: ['landing'],
     template: 'src/screens/landing/landing.html',
     filename: 'landing/index.html'
   })
 ]
};

Loaded project - odd-frogs.surge.sh
When setting paths starting with ../../src/ nothing works Tell me
what are the correct paths for images to specify?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mahmudchon, 2020-01-08
@mahmudchon

The correct path is where the image is finally available.
You are specifying relative paths that are relative to the location on the file system. But, on the site you get the root folder landing and everything next to it or just "not in it" will be unavailable on the site.

E
Eugene, 2020-01-08
@3vgeny90

img folder to landing folder

<img src="img/logo_piskel.png" alt="Logo Piskel" class="header_block-logo_icon">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question