0

这是我的配置文件,我尝试使用 html-loader 它对 .html 文件工作正常,但我现在正在尝试学习和使用 handlebarsjs,但它的工作方式不一样。我也尝试过使用 html-loader 的预处理器选项,我创建了一个函数来读取 .hbs 文件,但我不断收到错误消息。

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'],
      },            

    ],
  },
};
4

0 回答 0