Feature request: Async configuration via webpack.config.js

Feature request: Async configuration via webpack.config.js

Webpack version:
1.12.2

Please tell us about your environment:
Linux (OS independent problem)

Current behavior:
Configuration in webpack.config.js must define an object as module.exports.

Expected/desired behavior:
Configuration in webpack.config.js should also support async resolving of module.exports (e.g. by assigning a promise, future and/or callback to module.exports).

What is the motivation / use case for changing the behavior?
I stepped upon the same problem as described in defineplugin-from-async.

In my case I would like to include some git information (branch, last commit, current value of git-describe) as a constant into the bundled javascript code. With help of nodegit, it is relatively simple to retrieve this – but nodegit is an asynchronous node library.

While there is a work-around (by running webpack through the node API, see link above), my feeling is that allowing an async configuration webpack would simplify more advanced use-cases.

Author: Fantashit

2 thoughts on “Feature request: Async configuration via webpack.config.js

  1. For reference, for anyone stumbling here, returning a promise like what @sokra said looks something like this:

    const configPromise = new Promise(function(resolve, reject) {
    
        // ... do async stuff ...
    
        // then at some point call `resolve()` with the config object:
        resolve({
            entry: { /* ... */ },
            resolve: { /* ... */ },
            // etc
        })
    })
    
    module.exports = configPromise

Comments are closed.