We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当我们引入一个npm包的时候,我们知道在js是怎么写的,如果是浏览器就import xxx from 'xxx', 如果在node里面就是const xxx = require('xxx'),大家应该也知道引入一个npm包,npm会从package.json里面的 main 字段读取文件。
import xxx from 'xxx'
const xxx = require('xxx')
main
但是现在我又学到了可能还会有browser和module字段,这三个字段都可以用来当作npm读取文件的凭据,那它们优先级如何呢?
browser
module
定义了 npm 包的入口文件
定义一个针对 es6 模块及语法的入口文件
es6
指定供浏览器使用的入口文件
browser > module > main
module > main
package.json 中 你还不清楚的 browser,module,main 字段优先级
The text was updated successfully, but these errors were encountered:
No branches or pull requests
当我们引入一个npm包的时候,我们知道在js是怎么写的,如果是浏览器就
import xxx from 'xxx'
, 如果在node里面就是const xxx = require('xxx')
,大家应该也知道引入一个npm包,npm会从package.json里面的main
字段读取文件。但是现在我又学到了可能还会有
browser
和module
字段,这三个字段都可以用来当作npm读取文件的凭据,那它们优先级如何呢?main
定义了 npm 包的入口文件
module
定义一个针对
es6
模块及语法的入口文件browser
指定供浏览器使用的入口文件
总结
browser > module > main
browser
字段是无效的module > main
main
字段有效。参考
package.json 中 你还不清楚的 browser,module,main 字段优先级
The text was updated successfully, but these errors were encountered: