未生成Html webpack插件html文件

时间:2018-04-16 14:02:46

标签: reactjs plugins webpack

我刚开始使用webpack,我想使用html-webpack-plugin自动生成index.html文件。

我的webpack.config.js:

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

module.exports = {
    plugins: [
        new HtmlWebpackPlugin({
            hash: true
        })
    ]
}

enter image description here

我执行" npm run dev"等于webpack --mode开发,只生成了1个文件" main.js"。

我没有看到任何HTML文件,你能帮我吗?

webpack:4.5.0 html-webpack-plugin:3.2.0

提前致谢

2 个答案:

答案 0 :(得分:1)

尝试使用条目

entry: {
  main: [
    './src/'
  ]
},

答案 1 :(得分:0)

我发现了问题

您只需要在输出中指定路径,因为HtmlWebpackPlugin正在寻找路径

output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
},