html-webpack-plugin:如何将参数注入模板

问题描述 投票:1回答:4

我正在尝试将标题传递给html-webpack-plugin,但它根本没有创建标题标签:(

有人可以告诉我问题出在哪里

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
    }
};

这里是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>

当我启动webpack服务器时没有注入标题吗?

webpack html-webpack-plugin
4个回答
4
投票

尝试在您的html文件中使用此<title><%= htmlWebpackPlugin.options.title %></title>。作为参考,您可以在我的存储库index.html中检查webpack-setup文件。


1
投票

此问题已在此处报告Title not working. #176

如果要添加动态<title>标签,则应使用ejsjade,...]之类的模板语言>


0
投票

只需将您的index.html模板文件重命名为扩展名index.ejs


-1
投票

您是否尝试过将标题标签注入模板html文件./src/index.html

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.