2016-11-04 80 views
1

我試圖通過標題的HTML的WebPack-插件,但它不會在創建標題標籤的所有:(的WebPack HTML-的WebPack-插件標題不起作用

有人可以告訴我問題出在哪裏

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服務器標題沒有注入?

回答

0

這個問題已經在這裏報道Title not working. #176

如果您要添加的動態<title>代碼,則應使用模板語言像ejsjade,...

1

在HTML文件試試這個<title><%= htmlWebpackPlugin.options.title %></title> 。作爲參考,您可以在我的回購webpack-setup中檢查index.html文件。