简体   繁体   中英

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 " ?

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']
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM