How does webpack resolve imports from node_modules?

我的未来我决定 提交于 2019-12-05 10:05:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!