[英]This plugin file is using both CommonJS and ES6 module systems together which we don't support
[英]Publishing both es6 and commonjs with subfolders
lib
文件夾, https://davidwells.io/blog/publishing-flat-npm-packages-for-easier-import-paths-smaller-consumer-bundle-尺寸/ 我可以用CommonJS的指定主文件"main": "./index.js"
,並與ES6 "module": "./index.es.js"
中package.json
。
但是,當我導入my-package/myfile
時,它如何工作? 是使用myfile.js還是myfile.es.js
為什么不能指定子文件夾而不是單個主文件?
在您提到的博客文章中,沒有太多魔術,他只是在node_modules/his-module/P.js
捆扎機需要一個入口,因為(理論上)這就是您擁有的位置
module.exports = {}
打包程序可以訪問您的函數的代碼。
如果您使用的是與emodule兼容的捆綁器(例如webpack或匯總),他們將讀取module
密鑰
import someFunction from 'your-module';
將導入es模塊,除非您使用的瀏覽器版本類似commonjs版本。
您也可以明確要求其他文件
import someFunction from 'your-module/lib/index.min.js';
無論您在這里要求什么文件,都會導入該文件。 如果在模塊后添加/
,那么您將違反主路徑或模塊路徑約定,並詢問所需的文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.