I'm trying to use a webpack plugin to convert a regular dependency into an external one.
I'm not sure I'm doing it right. I tried doing the following, but I'm getting an error:
import * as ExternalModule from 'webpack/lib/ExternalModule';
export class Externalizer {
apply(compiler) {
compiler.plugin('compilation', (compilation, params) => {
params.normalModuleFactory.plugin('before-resolve', async (request, callback) => {
return callback(null, new ExternalModule(request.request, 'commonjs'));
});
});
}
}
When trying to use this as a plugin, The error I'm getting is: TypeError: Cannot read property 'request' of undefined
from handleExternals
.
FWIW, it seems like ExternalModule
is not meant to be used like this, I solved my problem by implementing a custom externals
function in webpack.config.js
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