I'm using an array of config objects with webpack to run multiple builds, and I have a resolver plugin (thanks to the example at Is it possible to create custom resolver in webpack?). I'm wondering if, from within the resolver plugin, it's possible to access the specific config object that is currently being used by webpack. (I could do require('webpack.config.js')
, but then I get the array of all the config objects, and don't know which is currently being built.)
The use case: each config object represents a different "theme" for the project. The resolver plugin, when invoked via a specific require()
argument syntax, will search first in a particular "theme" directory for the required asset, and if it doesn't find it, will search in a "core" directory for the same asset. This allows a "theme" to override components in the application only when needed, and otherwise to reuse shared components. Moving that logic to the resolver makes it easy to add/remove components without changing a bunch of hardcoded dependencies.
The issue I'm trying to address is that the resolver plugin doesn't know which "theme" is currently being built, so it doesn't know which directory to search. I solved this originally by running webpack as a child process from Grunt, and defining an environment variable to represent the "theme" being built, but I'd prefer to keep Grunt out of the loop. I imagine it would also work if each config object defined its modulesDirectories with the "theme" directories first, and then "core" -- but that's more ad-hoc than I would like; ideally there would be an explicit definition and lookup of the "theme" for each task. Seems like there ought to be a way to reference the current webpack build config while it's running...?