当需要npm包时,包名中斜杠的含义是什么? [英] When doing require for npm package, what is meaning of slash in package name?

查看:502
本文介绍了当需要npm包时,包名中斜杠的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然需要非本地NodeJS模块,但模块名称中斜杠的含义是什么?

While "requiring" non-local NodeJS modules, what is the meaning of slash in module name?

示例:
来自ShellJS的
npm模块的github页面(链接: https://github.com/shelljs/shelljs#javascript

require(' shelljs / global');

require('shelljs / make');

在查看ShellJS github项目的目录结构时,我注意到 global.js make.js 都与 shell.js ,它是package.json的模块的主要入口点。那么斜杠在包名中意味着什么呢?在上面的例子中,如何解决全局和制造的路径?

Upon looking at the directory structure of ShellJS github project, I notice that both global.js and make.js are both at same level as shell.js which is the main entry point of the module as per its package.json. So what does the slash mean in the package name and how, in above example, is the path to "global" and "make" resolved?

推荐答案

斜线(主要用途)只是用于文件路径。

Slash (as it primary use), is just simply used for file paths.

require('shelljs / global')将加载 global.js 文件的脚本。

require('shelljs / make')将加载 make.js的脚本 file。

然而, require('shelljs')将加载<$ c的脚本$ C> shell.js 。
为什么?让我们看一下 package.json 的内容:它是main:./ shell.js神奇。

However, require('shelljs') will load script of shell.js. Why? Let's look at the content of package.json: It's "main": "./shell.js" that makes the magic.

这篇关于当需要npm包时,包名中斜杠的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆