N
N
Nikita Shchypylov2018-03-12 22:46:05
React
Nikita Shchypylov, 2018-03-12 22:46:05

Why is Webpack wrapping images incorrectly in a React project?

Hello everyone
Here is the webpack config:

const path = require("path");
const webpack = require("webpack");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpackDashboard = require("webpack-dashboard/plugin");
const friendlyErrorsPlugin = require("friendly-errors-webpack-plugin");

module.exports = {
  context: path.join(__dirname, "/"),
  entry: ["babel-polyfill", "./src/index.js"],
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].js"
  },
  devServer: {
    contentBase: "./public",
    historyApiFallback: true
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.scss$/,
        use: [
          {
            loader: "style-loader"
          },
          {
            loader: "css-loader"
          },
          {
            loader: "sass-loader"
          }
        ]
      },
      {
        test: /\.css/,
        use: ["style-loader", "css-loader"]
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader"
          }
        ]
      },
      {
        test: /\.(jpe?g|gif|jpg|png|svg|woff|ttf|wav|mp3)$/,
        loader: "file-loader"
      }
    ]
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: "./public/index.html",
      filename: "./index.html"
    }),
    new CopyWebpackPlugin([{ from: "public/img/*", to: "img" }], {}),
    new webpackDashboard(),
    new friendlyErrorsPlugin()
  ]
};

This is what public looks like:
5aa6d8d495a52169410711.jpeg
And this is what dist looks like after build:
5aa6d8ea26691678744803.jpeg
What's the problem? Why is another level created in dist?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Epifanov, 2018-03-12
@Nikulio

the problem is here
try this code

new CopyWebpackPlugin([{ from: "public/img", to: "img" }], {})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question