【问题标题】:Webpack html-webpack-plugin is not workingWebpack html-webpack-plugin 不工作
【发布时间】:2019-12-18 00:53:14
【问题描述】:

当我运行命令npm run build 时,我希望index.html 应该被复制到dist 中,就像本教程在10:00 一样: https://www.youtube.com/watch?v=TzdEpgONurw&t=602s

但是什么也没发生,没有警告也没有错误。 这是配置:

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

module.export ={
    mode: 'development',
    module: {
        rules: [
            {
                test: /.html$/,
                use: [
                    {
                        loader: 'html-loader',
                        options: {minimize: true}
                    }
                ]
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html',
            filename:'./index.html'
        }),
    ],
}

这是我的完整代码: https://github.com/wickedrahul/webpackFourSetup

【问题讨论】:

  • 我花了一段时间才弄明白 :) 你在 webpack 中有错字 module.exports 而不是 module.export。还有一件事 - template: './src/index.html'filename: index.html
  • @GrzegorzT。哎呀,错字确实是问题所在,我会厌恶自己,即使在我浪费的几个小时内也没有弄清楚这一点:) index.html 没关系,它表示它将被复制到的目的地。

标签: webpack webpack-4 html-webpack-plugin


【解决方案1】:

正如 Grzegorz T 所建议的,这是一个错字。已将 module.export 更正为 module.exports 以解决问题。

【讨论】: