问题
When I need a library from my node_modules
folder I do something like this:
import angular from 'angular';
import $ from 'jquery;
How does webpack know what file(s) it really has to import? Guess there's some kind of strategy what files it's going to check?
回答1:
Webpack loops over resolvers to find the file you requested. It goes over resolve templates to figure out the exact path.
If you try to import a module that doesn't exist you'll see the error trace outlining all the paths it tried to use to find the file but failed.
Resolvers are a powerful configuration tool that could help you develop better code. I really appreciate that resolvers allow me to drop relative paths and use more developer-friendly ES6 imports.
I hope that helps.
来源:https://stackoverflow.com/questions/37875592/how-does-webpack-resolve-imports-from-node-modules