How to exclude a module from webpack, and instead import it using es6

Cart picture Cart · Sep 25, 2018 · Viewed 9k times · Source

I am currently using webpack to bundle up a javascript file with react. This file also has another import statement to another module within my project

import { MyModule} from './MyModuleFile.js'

Is there a way to exclude MyModule.js from the webpack bundle, and instead keep the import as is?

Answer

Tofandel picture Tofandel · Jun 8, 2019

What you're after is the externals option in your webpack.config.js

module.exports = {
  //...
  externals: {
     './MyModuleFile': 'MyModule',
  }
};