Considering there's Webpack config
...
entry: {
'bundle-with-dependency-a': 'common-entry.js',
'bundle-with-dependency-b': 'common-entry.js'
},
resolve: {
alias: {
'dep-a': ...,
'dep-b': ...
},
},
and I would expect in common-entry.js
something like this:
require('dep-' + entryName.slice(-1));
I.e. I want to provide the definition for particular require from config.
The problem is that there may be more than 2 dependency options, I avoid copypasting. And I'm about to do this at build time, instead of requiring the chunks with JSONP.
How can this require be made dynamic?
The only option I've got here is to have different configuration for each dep, but this requires to make multiple Webpack passes instead of single. Not very convenient.
Using the imports-loader
:
webpack.config.js
{
entry: {
'bundle-with-dependency-a': 'imports?depName=>"dep-a"!./common-entry.js',
'bundle-with-dependency-b': 'imports?depName=>"dep-b"!./common-entry.js',
},
// ...
}
The depName
variable will then be exposed to the common-entry.js
module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With