2016-07-23 42 views
0

我需要知道構建的哈希值,所以我想捕捉它在回調函數:爲什麼我用Webpack獲得2個版本?

const compiler = webpack(webpackConfig, function (err, stats) { 
    debug("Hash", stats.hash) 
}) 

但是,當我這樣做奇怪的事情發生了:我得到2建立並能只捕獲1個散列 - 顯然我需要另一個,而不是回調中的那個。

輸出具有回調時:

app:server Hash +7s ea34c7a4d34baae1c353 
webpack built d796ba7633cf5b1023a0 in 6673ms 
Hash: ea34c7a4d34baae1c353 
Version: webpack 1.13.1 
Time: 6649ms 
Asset  Size Chunks    Chunk Names 
app.ea34c7a4d34baae1c353.js 1.27 MB  0 [emitted] app 
1.counter.ea34c7a4d34baae1c353.js  247 kB  1 [emitted] counter 
vendor.ea34c7a4d34baae1c353.js  389 kB  2 [emitted] vendor 
app.ea34c7a4d34baae1c353.js.map 1.54 MB  0 [emitted] app 
1.counter.ea34c7a4d34baae1c353.js.map  303 kB  1 [emitted] counter 
vendor.ea34c7a4d34baae1c353.js.map  466 kB  2 [emitted] vendor 
favicon.ico 24.8 kB   [emitted] 
index.html 595 bytes   [emitted] 
Child html-webpack-plugin for "index.html": 
Asset Size Chunks  Chunk Names 
index.html 553 kB  0 
webpack: bundle is now VALID. 
    Hash: d796ba7633cf5b1023a0 
Version: webpack 1.13.1 
Time: 6673ms 
Asset  Size Chunks    Chunk Names 
app.d796ba7633cf5b1023a0.js 1.17 MB  0 [emitted] app 
vendor.d796ba7633cf5b1023a0.js  389 kB  1 [emitted] vendor 
app.d796ba7633cf5b1023a0.js.map 1.42 MB  0 [emitted] app 
vendor.d796ba7633cf5b1023a0.js.map  466 kB  1 [emitted] vendor 
favicon.ico 24.8 kB   [emitted] 
index.html 595 bytes   [emitted] 
Child html-webpack-plugin for "index.html": 
Asset Size Chunks  Chunk Names 
index.html 553 kB  0 
webpack: bundle is now VALID. 

輸出時,沒有回調:

Hash: c5e31d1eb986b7ef318d 
Version: webpack 1.13.1 
Time: 3891ms 
Asset  Size Chunks    Chunk Names 
app.c5e31d1eb986b7ef318d.js 1.26 MB  0 [emitted] app 
1.counter.c5e31d1eb986b7ef318d.js 30.6 kB  1 [emitted] counter 
vendor.c5e31d1eb986b7ef318d.js  389 kB  2 [emitted] vendor 
app.c5e31d1eb986b7ef318d.js.map 1.54 MB  0 [emitted] app 
1.counter.c5e31d1eb986b7ef318d.js.map 37.9 kB  1 [emitted] counter 
vendor.c5e31d1eb986b7ef318d.js.map  466 kB  2 [emitted] vendor 
favicon.ico 24.8 kB   [emitted] 
index.html 595 bytes   [emitted] 
Child html-webpack-plugin for "index.html": 
Asset Size Chunks  Chunk Names 
index.html 553 kB  0 
webpack: bundle is now VALID. 

文件:https://github.com/davezuko/react-redux-starter-kit/blob/master/server/main.js

回答

0

好,我找到了......在的WebPack的來源,如果有一個回調給webpack(options, callback)然後它自動運行:

function webpack(options, callback) { 
    ... 
    if(callback) { 
     ... 
     compiler.run(callback); 
    } 
    return compiler; 
} 

如果有人想通過添加一個plugin如下添加回調做到這一點:

compiler.plugin("done", stats => { 
    debug(hash) 
}) 
相關問題