jantimon / html-webpack-plugin

Simplifies creation of HTML files to serve your webpack bundles
MIT License
10.71k stars 1.31k forks source link

multi-page behavior illogical? #1834

Closed nordbit closed 10 months ago

nordbit commented 10 months ago

Current behaviour šŸ’£

var path = require('path');
var HtmlWebpackPlugin = require('../..');
var webpackMajorVersion = require('webpack/package.json').version.split('.')[0];

module.exports = {
  context: __dirname,
  entry: {
    first: './first.js',
    second: './second.js'
  },
  output: {
    path: path.join(__dirname, 'dist/webpack-' + webpackMajorVersion),
    publicPath: '',
    filename: '[name].js'
  },
  module: {
    rules: [
      { test: /\.css$/, use: ['style-loader', 'css-loader'] },
      { test: /\.png$/, type: 'asset/resource' }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: '[name].html'
    })
  ]
};

generates two html files, first.html and second.html - both with EXACTLY same content

<script defer="defer" src="first.js"></script><script defer="defer" src="second.js">

Expected behaviour ā˜€ļø

first.html:

<script defer="defer" src="first.js"></script>

second.html:

<script defer="defer" src="second.js"></script>

Reproduction Example šŸ‘¾

same as in examples foder in repository

Environment šŸ–„

Node.js v20.10.0
linux 6.7.0-rc2
npm 10.2.3
html-webpack-plugin@5.5.4
alexander-akait commented 10 months ago

In such case you need to use excludeChunks or you can setup more complex logic using multi compiler mode - create three configuration - common, first and second and use dependencies https://webpack.js.org/configuration/other-options/#dependencies, feel free to feedback