Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

81
Views
Webpack doesn't load images from html and css

My images from .scss file are shown in "dist/images", but they do not load on localhost. And images from html file ( kind) are not read at all, it seems to be loaded in "dist", but not "dist/images" and it is not visible on the page.

Can anyone see what is incorrect in my config?

Here is the config:


const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");


const isProduction = process.env.NODE_ENV == "production";

const config = {
  entry: "./src/index.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bundle.js",

  },
  devtool: "source-map",
  devServer: {
    open: true,
    host: "localhost",
    hot: true,
  },
  plugins: [new MiniCssExtractPlugin(),
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: "index.html",
    }),
  ],
  
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/i,
        loader: "babel-loader",
        exclude: /node_modules/,
      },
      {
                test: /\.(sass|less|css|scss)$/,
                use: [
                    
                    "css-loader", "sass-loader"],
            },
     {
        test: /\.(jpe?g|png|svg)$/,
        use: [{   
          loader: 'file-loader',
          options: {
            name: '[hash].[ext]',
            outputPath: 'images'
          },
        }]
      },
    ],
  },
};

module.exports = () => {
  if (isProduction) {
    config.mode = "production";

    config.plugins.push(new MiniCssExtractPlugin());
  } else {
    config.mode = "development";
  }
  return config;
};
  • dist
  • node_modules
  • src
    • assets
      • image
    • scss
    • index.js
  • index.html
  • package.json
  • webpack.config.js
7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.