在Webpack构建期间未将Favicon添加到构建文件夹

时间:2019-04-18 20:42:41

标签: reactjs webpack webpack-4

我正在尝试将图像放入dist文件夹,但未显示。

我包括了copy-webpack-plugin,我认为它可以使它工作。在构建过程中,我确实收到一条警告消息:“警告无法在” / Users / developer / Desktop / RecruitsPro / client / public中找到/ Users / developer / Desktop / RecruitsPro / client / public” >

webpack.config.js

var webpack = require('webpack');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
const helpers = require('./helpers');

const VENDOR_LIBS = [
  'axios',
  'ordinal',
  'react',
  'react-activity',
  'react-avatar',
  'react-dom',
  'react-easy-chart',
  'react-is',
  'react-modal',
  'react-redux',
  'react-router-dom',
  'react-stripe-checkout',
  'react-window-size',
  'redux',
  'redux-form',
  'redux-thunk'
];

module.exports = {
  entry: {
    bundle: './client/app/index.js',
    vendor: VENDOR_LIBS
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].[chunkhash].js'
  },
  module: {
    rules: [
      {
        use: 'babel-loader',
        test: /\.js$/,
        exclude: /node_modules/
      },
      {
        use: ['style-loader', 'css-loader'],
        test: /\.css$/
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './client/public/index.html'
    }),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
    }),
    new CopyWebpackPlugin([{
      from: helpers.root('client/public')
    }])
  ]
};

helpers.js

const path = require('path');

// Helper functions
function root(args) {
  args = Array.prototype.slice.call(arguments, 0);
  return path.join.apply(path, [__dirname].concat('../', ...args));
}

exports.root = root;

我希望图片能显示出来。

1 个答案:

答案 0 :(得分:0)

对于任何好奇的人,我必须将此代码添加到我的module.rules数组中。

  {
    test: /\.png$/,
    loader: 'file-loader'
  }