2017-03-14 3 views
4

私はWebpack 2 Node APIを使用しており、を使用してrun()メソッドを約束したいと思います。Webpackコンパイラインスタンスの約束?

import Promise from 'bluebird' 
import webpack from 'webpack' 

const compiler = webpack(config) 
const runAsync = Promise.promisify(compiler.run) 

runAsync().then(stats => { 
    console.log('stats:', stats) 
}).catch(err => { 
    console.log('err:', err) 
}) 

私は取得していますエラーは次のとおりです。

[TypeError: self.applyPluginsAsync is not a function]

だから私はWebPACKのコードはブルーバードpromisificationと互換性のある方法で書かれていないことを推測しています。

ウェブパックのrun()メソッドを約束する他の方法がある場合は?

これらのコールバックとifのステートメントは私に迷惑をかけています。

答えて

3

compilerpromisifyメソッドのコンテキストとして渡す必要があります。

const runAsync = Promise.promisify(compiler.run, { context: compiler }); 

かそこらのようにそれを呼び出す:

runAsync.call(compiler).then(stats => {... 

ブルーバードDocsから:

Note that if the node function is a method of some object, you can pass the object as the second argument like so:

var redisGet = Promise.promisify(redisClient.get, {context: redisClient}); 
redisGet('foo').then(function() { 
    //... 
});