juniorgarcia juniorgarcia -4 years ago 67
Node.js Question

webpack: how to get JavaScript from "bower_components", not from "node_modules"

Due the use of

main-bower-files
as part of the compiling tasks using Gulp, I can't
require
modules using webpack from
node_modules
dir because I would mess the CSS's / images / fonts processing tasks in my current asset system. So, how can I tell webpack "when I
require
something, search into
bower_components
folder instead in
node_modules
"
?

Answer Source

You can use the resolve.modules option in your config:

resolve: {
  modules: ['bower_components']
}

With this it won't check node_modules at all, but if you'd like to fallback to node_modules when the module is not found in bower_components, you can add it as well, the priority is from left to right:

resolve: {
  modules: ['bower_components', 'node_modules']
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download