Wednesday, June 6, 2018

How to convert a regular commonjs module to an external via a webpack plugin?

Leave a Comment

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.

1 Answers

Answers 1

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 Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment