N
N
Nikita Shchypylov2018-03-06 13:46:02
React
Nikita Shchypylov, 2018-03-06 13:46:02

Why doesn't CopyWebpackPlugin copy images?

Hello everyone
Config:

const path = require("path");
const webpack = require("webpack");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');


const BUILD_DIR = path.resolve(__dirname, './dist');

module.exports = {
  context: path.join(__dirname, '/'),
  entry: ["babel-polyfill", "./src/index.js"],
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].js"
  },
  devServer: {
    contentBase: "./dist",
    // outputPath: BUILD_DIR,
    // hot: true,
    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|png|svg|woff|ttf|wav|mp3)$/, loader: "file"}
    
    ]
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: "./public/index.html",
      filename: "./index.html"
    }),
    new CopyWebpackPlugin([
      {from: './src/img/*', to: './dist/img'}
    ], {})
  ]
};

Structure:
5a9e7138ebcc4482334784.jpeg
In the code I use this:
let imgUrl =  stories[key].img ? stories[key].img : "/img/no_image.jpg";

But it gives me "not found".
Why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
ozknemoy, 2019-01-27
@ozknemoy

in addition to any overhead on the stack, I just copy folders with files

const CopyWebpackPlugin = require('copy-webpack-plugin');
// WriteFilePlugin  needed only for webpack 3-4 and webpack dev-server
const WriteFilePlugin = require('write-file-webpack-plugin');
plugins: [
  ...
  new WriteFilePlugin(),
  new CopyWebpackPlugin([
        {from: 'files', to: 'files'},
        {from: 'images-2x', to: 'images-2x'},
        {from: 'images', to: 'images'},
      ]),
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question