2016-11-30 38 views
1

我想爲我的js塊使用html-webpack-plugin 只有。 Bundle.css被提取文本 - 插件生成:如何從html-webpack-plugin生成的index.html中排除bundle.css?

new ExtractTextPlugin({filename: 'bundle.css, allChunks: true}) 

HtmlWebpackPlugin選項:

new HtmlWebpackPlugin({template: 'template/tpl.html', inject: true}) 

我tpl.html看起來是這樣的:

<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
 
    <title>Cash Management</title> 
 
    <link href="getResource?resource=build/bundle.css&mediaType=text/css" rel="stylesheet"> 
 
</head> 
 
<body> 
 
<div id='root' /> 
 
</body> 
 

 
</html>

我想看看類似的東西在我的index.html E本:

<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
 
    <title>Cash Management</title> 
 
    <link href="getResource?moduleName=cm-ui&resource=build/bundle.css&mediaType=text/css" rel="stylesheet"> 
 
</head> 
 
<body> 
 
<div id='root' /> 
 
</body> 
 
    <script href="getResource?moduleName=cm-ui&resource=build/common.js" type="text/javascript"></script> 
 
    <script href="getResource?moduleName=cm-ui&resource=build/bundle.js" type="text/javascript"></script> 
 
</html>

可有人請點我在正確的方向?

+0

通過快速瀏覽,我在鍵'allCunks:true'中看到了一個拼寫錯誤。 =>'allChunk:true' –

+0

謝謝,解決了! –

回答

1

您可以使用html-webpack-exclude-assets-plugin

有了它,你可以排除其防止它們被自動粘貼的資產。 您還可以使用lodash語法向您的模板插入路徑。

<link href="getResource?resource=<%= htmlWebpackPlugin.files.css[0] %>&mediaType=text/css" rel="stylesheet"> 
+0

看起來很好的解決方案!謝謝你! –

相關問題