Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html-webpack-plugin: How to inject parameters like title into the template

I am trying to pass title to html-webpack-plugin but it does not create title tag at all :(

Can somebody show me where is the problem

webpack.js

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

module.exports = {
    entry: ['./src/app/main.ts'],
    output: {
        filename: 'build.js',
        path: 'dist'
    },
    resolve: {
        root: __dirname,
        extensions: ['', '.ts', '.js', '.json']
    },
    resolveLoader: {
        modulesDirectories: ["node_modules"]
    },
    devtool: "source-map",
    plugins: [
        new HtmlWebpackPlugin({
            title : 'Hello',
            template: './src/index.html',
            inject: 'body',
            hash: true,
        })
    ],
    module: {
        loaders: loaders
    }
};

And here is index.html

<!doctype html>
<html lang="en">
<head>
    <noscript>
        <meta http-equiv="refresh" content="0; url=https://en.wikipedia.org/wiki/JavaScript">
    </noscript>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
</head>
<body>
    <ui-view></ui-view>
</body>
</html>

When I start webpack server title is not injected?

like image 482
Miomir Dancevic Avatar asked Nov 04 '16 10:11

Miomir Dancevic


2 Answers

Try this <title><%= htmlWebpackPlugin.options.title %></title> in your html file. For reference you can check index.html file in my repos webpack-setup.

like image 126
Samar Panda Avatar answered Nov 02 '22 22:11

Samar Panda


This issue has been reported here Title not working. #176

If you want to add the dynamic <title> tag, you should use a template language like ejs, jade, ...

like image 2
iarroyo Avatar answered Nov 02 '22 22:11

iarroyo