Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack ignore import

Tags:

webpack

I am importing a third-party module which imports another module:

import fetch from "cross-fetch";

I would like to tell Webpack to ignore/remove this import because the variable fetch already exists in global namespace. Is that possible?

like image 847
Mick Avatar asked Aug 08 '26 16:08

Mick


1 Answers

You can specify that some module is in the global env with externals.

// webpack.config.js

module.exports = {
  //...
  externals: {
    'cross-fetch': 'fetch' 
  }
};
like image 102
felixmosh Avatar answered Aug 11 '26 12:08

felixmosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!