Move resource folder to public directory using webpack

I am using Webpack for the first time. Currently, everything is serving well. My problem is when I try to create a folder dist. I am currently receiving files index.htmland bundle.js, but I cannot figure out how to move my resources to a folder dist.

I have a file downloader loaded, but it really doesn’t look like what I want, and none of the Google searches I ran tells me what I need to know. The following is the configuration file. Can anyone bring a horse to the water? Also, as soon as I run it, do I need to import all the images into my React components?

var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './app/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/'
  },
  module: {
    rules: [
      { test: /\.(js)$/, use: 'babel-loader' },
      { test: /\.scss$/, use: [ 'style-loader', 'css-loader', 'sass-loader' ]},
      { test: /\.(png|jpe?g|svg|)$/, use: { loader: 'file-loader', options: }}
    ]
  },
  devServer: {
    historyApiFallback: true,
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'app/index.html'
    })
  ]
};
+4
1

, Copy-Webpack-Plugin.

"app/assets/" "dist/assets/", :

  plugins: [
    new CopyWebpackPlugin([
      { from: 'app/assets', to: 'assets' }
    ])
  ]
+3

Source: https://habr.com/ru/post/1683292/


All Articles