webpack 配置 plugin 的 html-webpack-plugin 时候显示 path must be type of string

在学习 webpack 的时候碰到个配置 plugin 的问题,具体代码如下:

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

module.exports = {
    entry: path.join(__dirname, 'index'),
    output: {
            path: __dirname,
            filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.css$/,
                loaders: ['style', 'css']
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: 'use plugin'
        })
    ]
};

文件路径如下:


14945954-c93cac3f38e0b6e4.png
image.png

其中的 index.html 一开始是没有的 后续 webpack 编译生成的.
执行 webpack 的时候报错:


14945954-359aee870fbcca8f.png
image.png

后来看到一位博主给的解决办法:
14945954-4956479058aebb9e.png
image.png

plugin 配置里面加个 filename: 'index.html' 即可.

特此记录

猜你喜欢

转载自blog.csdn.net/weixin_33724046/article/details/90802881