模块modules 的区别"/>
npm包package和模块modules 的区别
package官方解释
A package is a file or directory that is described by a package.json file. A package must contain a package.json file in order to be published to the npm registry.
翻译:npm包可以是通过一个package.json描述的一个文件或者文件夹。一个npm包中必须包含package.json文件,因为这样才能发布到npm的官网上。
modules官方解释
A module is any file or directory in the node_modules directory that can be loaded by the Node.js require() function.
To be loaded by the Node.js require() function, a module must be one of the following:
- A folder with a package.json file containing a “main” field.
- A folder with an index.js file in it.
- A JavaScript file.
Note: Since modules are not required to have a package.json file, not all modules are packages. Only modules that have a package.json file are also packages.
翻译:node_modules文件夹中任何可以通过require()引用到的文件或者文件夹都可以称为模块。
为了可以通过require()引用到该模块,它必须具有以下特征之一:
- 文件夹中包含package.json并且有入口文件
- 一个文件夹中含有一个index.js文件
- 一个js文件(下面图中的例子)
提示:因为模块不必须有package.json文件,所以不是所有的npm模块都可以称为npm包,只有包含package.json文件的npm模块可以称为npm包。
官方地址:
更多推荐
npm包package和模块modules 的区别
发布评论