Webpack 5 Asset modules not creating images to dist folder when using handlebars-loader. How do i get it to output the images?

Viewed 264

This is my config file, I have tried with html-loader it works fine for .html files but i’m now trying to learn and use handlebarsjs its not working the same. I've also tried using the preprocessor option for html-loader whereby i created a function to read .hbs files but I keep getting errors.

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

module.exports = {
  entry: './src/index.js',
    plugins: [
    new HtmlWebpackPlugin({
      title: 'Output Management',
            template: './src/index.hbs'
    }),
  ],
    devtool: 'inline-source-map',
    devServer: {
    static: './dist',
        hot: true,
  },
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist'),
        publicPath:'/dist/',
        clean:true,
  },
    mode: 'development',
    module: {
    rules: [
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
            {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: 'asset/resource',
                generator: {
                    filename: 'assets/img/[hash][ext][query]'
                }
      },
            {
        test: /\.hbs$/i,
        use: ['handlebars-loader'],
      },            

    ],
  },
};
0 Answers
Related