[英]How does script tag resolves path to node_modules?
I was reading this Node.js In Action and there's this index.html
which references socket.io.js
from node_modules
folder (I believe). 我正在阅读这个Node.js In Action,这个
index.html
引用了node_modules
文件夹中的socket.io.js
(我相信)。
How does the following script tag resolves the path to the socket.io.js
when the node_modules
folder is one directory up from where the index.html
resides? 当
node_modules
文件夹是index.html
所在的目录之一时,以下脚本标记如何解析socket.io.js
的路径?
The script tag: 脚本标签:
<script src="/socket.io/socket.io.js" type="text/javascript"></script>
Socket.io reads the content of the socket.io-client/socket.io.js
file into a variable. Socket.io将
socket.io-client/socket.io.js
文件的内容读入变量。
Socket.io has access to your app's http server, it then listens to requests that would match the URL of something like '/socket.io/socket.io.js' and responds with the contents of that variable above Socket.io可以访问你的应用程序的http服务器,然后它会侦听与'/socket.io/socket.io.js'之类的URL匹配的请求,并响应上面那个变量的内容
You can see this in the socket.io source code : 你可以在socket.io源代码中看到这个:
When you include a module in your file, node first looks for the module in node_modules
folder in current directory. 在文件中包含模块时,节点首先在当前目录的
node_modules
文件夹中查找模块。 If it does not find it there then it moves to parent directory and looks for the module in node_modules
present in that directory, and it keeps moving up until it finds the required module. 如果它没有找到它,那么它将移动到父目录并在该目录中存在的
node_modules
查找该模块,并且它一直向上移动直到找到所需的模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.