Html-webpack-plugin: Bug: can't set title when your htmlwebpackplugin config has a template

Created on 30 Mar 2019  路  2Comments  路  Source: jantimon/html-webpack-plugin

Expected behaviour

Tell us what you would expect the html-webpack-plugin should.

when you set a template in your options, the html generated by plugin should insert the title your set;

Current behaviour

Tell us what the html-webpack-plugin does instead.

title is not work

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm, webpack, and html-webpack-plugin. Run the following to get it quickly:

mac

node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
npm --version
npm ls webpack
npm ls html-webpack-plugin

Config

Copy the minimal webpack.config.js to produce this issue:

module.exports = {
  entry: 'app.js',
  output: {
    path: 'dist',
    filename: 'index_bundle.js'
  },
  module: {
    rules: [
      ...
    ]
  }
  plugins: [
    new HtmlWebpackPlugin(),
    ...
  ]
}

Copy your template file if it is part of this issue:

<!DOCTYPE html>
<html>
    <head>
        <title>My App</title>
    </head>
    <body>
    </body>
</html>

Relevant Links

  • If your project is public, link to the repo so we can investigate directly.
  • BONUS POINTS: Create a minimal reproduction and upload it to GitHub. This will get you the fastest support.

Additional context

Add any other context about the problem here.

Most helpful comment

The title is part of the default template if you want to use your own you have to set the title by yourself - if think of it like a preset vs a custom solution

https://github.com/jantimon/html-webpack-plugin/blob/25465510df1633f76005f430b098cc7783e0495b/default_index.ejs#L5

All 2 comments

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

module.exports = {
entry: './pages/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js'
},
mode: 'none',
module:{
rules:[
{
test: /.txt$/,
use:['raw-loader']
}
]
},
plugins:[
new HtmlWebpackPlugin({
title: 'My app',
filename: 'assets/index.html',
// template: './pages/index.html',
inject: 'body',
minify: {
// collapseWhitespace: true,
// removeComments: true,
// removeRedundantAttributes: true,
// removeScriptTypeAttributes: true,
// removeStyleLinkTypeAttributes: true,
// useShortDoctype: true
},
hash: true
})

]
}
`

The title is part of the default template if you want to use your own you have to set the title by yourself - if think of it like a preset vs a custom solution

https://github.com/jantimon/html-webpack-plugin/blob/25465510df1633f76005f430b098cc7783e0495b/default_index.ejs#L5

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hackteck picture hackteck  路  3Comments

hp8wvvvgnj6asjm7 picture hp8wvvvgnj6asjm7  路  3Comments

NeverwinterMoon picture NeverwinterMoon  路  3Comments

amorphius picture amorphius  路  3Comments

lcxfs1991 picture lcxfs1991  路  4Comments