I've seen some npm packages (vue for example) have a pkg.module
field in their package.json. Is "module"
an official npm property or is this a convention of some kind? Is there documentation for this somewhere? What's it for? esnext path? Unbundled module path?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Is
"module"
an official npm property or is this a convention of some kind?
It's a proposal, but likely to be supported due to de facto usage.
Is there documentation for this somewhere?
There is, in fact, and it can be found right here and later removed here.
What's it for?
ES6 Module Interoperability in Node. Additional discussion can be found here and here. And here's a blog post from Rich Harris talking more about it.
回答2:
This is used by bundler tools for ESM (ECMAScript Module) detection. The Rollup documentation says it pretty well:
If your
package.json
file also has amodule
field, ES6-aware tools like Rollup and webpack 2 will import the ES6 module version directly.
Further discussion of pkg.module
is on the Rollup Github Wiki.