このローダーを使用してカスタムデータを.htmlテンプレートに挿入しようとしましたが、成功しませんでした。私たちは資産をうまく構築して注入することができましたが、動的データを渡す機能は機能しませんでした。このレポで提供されているサンプルを見ると、options.titleがどのようにテンプレートに渡されるのか分かりません。html-webpack-pluginを使用してテンプレートにデータを挿入できません
私はこのプラグインと非常に簡単です。このスターターキットを、使用しています:ここでhttps://github.com/AngularClass/NG6-starter
は、関連する依存関係のバージョンです:
"webpack": "^2.2.1"
"html-webpack-plugin": "^2.29.0"
はwebpack.configから関連するセクションをコピーします。 JS:
module.exports = {
devtool: 'source-map',
entry: {
app: [
'babel-polyfill',
path.join(__dirname, 'client', 'app/app.js')
]
},
module: {
loaders: [
{ test: /\.js$/, exclude: [/app\/lib/, /node_modules/], loader: 'ng-annotate-loader!babel-loader' },
{ test: /\.html$/, loader: 'raw-loader' }, // have also tried with the html-loader
{ test: /\.(scss|sass)$/, loader: 'style-loader!css-loader!sass-loader' },
{ test: /\.css$/, loader: 'style-loader!css-loader' }
]
},
plugins: [
// Injects bundles in your index.html instead of wiring all manually.
// It also adds hash to all injected assets so we don't have problems
// with cache purging during deployment.
new HtmlWebpackPlugin({
template: 'client/index.html',
// inject: 'body',
// hash: true,
title: 'TEST!!!!!!!!!!!',
options: {
title: "TEST!!!!!!!!!!!!!*"
},
chunks: ['vendor', 'app']
}),
// Automatically move all modules defined outside of application directory to vendor bundle.
// If you are using more complicated project structure, consider to specify common chunks manually.
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
minChunks: module => /node_modules/.test(module.resource)
})
]
};
テンプレートファイル
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="description" content="NG6-Starter by @AngularClass">
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<base href="/">
</head>
<body ng-app="app" ng-strict-di ng-cloak>
<%= htmlWebpackPlugin.options.title %>
<%= htmlWebpackPlugin.title %>
<%= title %>
<%= '\<\%\= htmlWebpackPlugin.title \%\>' %>
<%= '\<\%\= htmlWebpackPlugin.options \%\>' %>
</body>
</html>
。それはまだ同じ試練だった。上記で提供したスターターキットで作業することができれば、あなたは悪いことになるでしょう – Detuned
'html-webpack-plugin'は時代遅れで動作しませんでした。それをアップグレードすると、うまく動作します。 –
それは残念ながら問題ではありませんでした。これは 'html-webpack-plugin'がローダーと組み合わせてファイルをどのように扱うのかの問題であった。私は必要な修正へのリンクを掲載しました... – Detuned