Is there a webpack dependency object that accepts content instead of a file path? (plugin development)

The webpack plugin can convert require("something")

to something like __webpack_require__(165)

using CommonJsRequireDependency

like in lib / dependencies / CommonJsRequireDependencyParserPlugin.js # L74-L82 . CommonJsRequireDependency

takes request

(file path) and range

.

Is there any dependency object that instead of passing the file path takes the file itself? (I want to dynamically generate content).

PS: I had this question while implementing a plugin that injects a dynamically generated dependency on the fly.

+3


source to share


1 answer


I don't know if it is possible to make the context of the require () statement the most dynamic outside of the dynamic context content included in webpack ( http://webpack.github.io/docs/context.html )

However, I ran into a similar issue when dealing with generating config json based on environment variables. I ended up creating a custom loader that would generate dynamic content. In the end, it looked something like this:

var config = require('config!.)

      



and then my custom loader was something like this:

module.exports = function(source) {
    this.cacheable();
    var callback = this.async();

    myLib.getConfig()
        .then(function(config) {
            callback(null, config)
        });
}

      

+1


source







All Articles