2016-08-17 91 views
3

HtmlWebpackPlugin無法正常輸出到輸出的WebPack導演:我有這樣的設置:HtmlWebpackPlugin無法正常輸出

var config = { 
    context: __dirname + '/client', 
    entry: { 
    main: [ 
     "./app.js" 
    ] 
    }, 
    output: { 
    path: __dirname + "./public", 
    filename: "dist.js" 
    }, 
    devtool: "source-map", 
    module: { 
    loaders: [ 
     { 
     test: /\.js?$/, 
     loader: 'babel-loader', 
     include: [ 
      path.resolve(__dirname, 'client'), 
     ], 
     exclude: /node_modules/ 

     }, 
     { 
     test: /\.less$/, 
     loader: "style!css!less" 
     }, 
     { 
     test: /\.css/, 
     loader: "style!css" 
     } 
    ] 
    }, 
    resolve: { 
    // you can now require('file') instead of require('file.js') 
    extensions: ['', '.js', '.json'] 
    }, 
    plugins: [ 
    new HtmlWebpackPlugin({ 
     title: 'Webpack demo' 
    }) 
    ] 
} 

但是沒有index.html文件輸出到公衆。

我剛剛得到這個消息:

 Asset  Size Chunks    Chunk Names 
    dist.js  530 kB  0 [emitted] main 
dist.js.map  638 kB  0 [emitted] main 
index.html 181 bytes   [emitted] 
    [0] multi main 28 bytes {0} [built] 
    + 130 hidden modules 
Child html-webpack-plugin for "index.html": 
     + 3 hidden modules 
+0

其產生的index.html我可以在你的消息'的index.html 181個字節見[發出]' – Kasiriveni

回答

1

HtmlWebpackPlugin簡化的HTML文件的創建,以滿足您的WebPack束。這對於webpack軟件包特別有用,其中中的hash可更改每個編譯。您可以讓插件爲您生成一個HTML文件,使用lodash模板提供您自己的模板,或使用您自己的裝載器您的

wbpack.config.js

const HtmlWebpackPlugin = require('html-webpack-plugin'); 
 
const path=require('path'); 
 

 
var webpackConfig = { 
 
    entry: './src/index.js', 
 
    output: { 
 
    path:path.resolve(__dirname,'dist'), 
 
    filename: 'index_bundle.js' 
 
    }, 
 
    plugins: [new HtmlWebpackPlugin()] 
 
}; 
 

 
module.exports = webpackConfig;

輸出:

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <meta charset="UTF-8"> 
 
    <title>Webpack App</title> 
 
    </head> 
 
    <body> 
 
    <script type="text/javascript" src="index_bundle.js"></script></body> 
 
</html>

可以執行定製也是這樣 configuration

new HtmlWebpackPlugin({ 
    title:'sample text', 
    filename:'sample.index' 
)