Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html webpack plugin html file not generated

I just started with webpack, and I want to automatically generate index.html file using html-webpack-plugin.

My 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

I execute "npm run dev" equals to webpack --mode development, and only 1 file generated "main.js".

I don't see any html files, could you please help me?

webpack: 4.5.0 html-webpack-plugin: 3.2.0

Thanks in advance

like image 926
D.Mark Avatar asked May 20 '26 02:05

D.Mark


2 Answers

Try using the entry

entry: {
  main: [
    './src/'
  ]
},
like image 98
Miłosz Avatar answered May 21 '26 19:05

Miłosz


I found the issue

You just need to specify path in output, because HtmlWebpackPlugin is looking for path

output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js'
},
like image 27
D.Mark Avatar answered May 21 '26 20:05

D.Mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!