Webpack compiler instance promotion?

I am using the Webpack 2 Node API and I would like to promise a method run()using bluebird .

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)
})

The error I get is:

[TypeError: self.applyPluginsAsync is not a function]

So, I assume that the webpack code is not written in a way that is compatible with the bluebird promise.

If there is another way to promise the webpack run().. method ?

All of these callbacks and expressions are iflistening to me.

+4
source share
1 answer

You need to pass compileras a method context promisify.

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

Or name it like this:

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

Bluebird Docs:

, node , :

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

Source: https://habr.com/ru/post/1672229/


All Articles