2017-03-14 1 views
4

나는 Webpack 2 Node API을 사용 중이므로 bluebird을 사용하여 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]

그래서 나는 웹팩 코드 블루 버드 promisification와 호환 방식으로 기록되지 않습니다 같은데요.

webpack의 run() 방법을 약속하는 다른 방법이 있다면 ...?

이러한 모든 콜백과 if 문이 나를 괴롭 히고 있습니다.

답변

3

promisify 메서드의 컨텍스트로 compiler을 전달해야합니다.

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() { 
    //... 
});