xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

npm package.json exports filed All In One

npm package.json exports filed All In One

https://docs.npmjs.com/files/package.json

https://docs.npmjs.com/cli/v9/configuring-npm/package-json/#main

https://docs.npmjs.com/cli/v9/configuring-npm/package-json#workspaces

https://docs.npmjs.com/cli/v9/configuring-npm/package-json#exports ???

Node.js exports

module.exports vs. exports

https://www.freecodecamp.org/news/node-js-module-exports-vs-exports-ec7e254d63ac/

demos


{
  "main": "./index.js",
  "exports": "./index.js"
}
{
  "exports": {
    ".": "./index.js",
    "./subpath.js": "./subpath.js"
  }
}

🚀 exports 条件导出

. 表示当前目录

既可以在支持 import 环境的项目 import 它;
也可以在支持 require 的项目 require 它;

"exports": {
    ".": {
        "import": "./index.mjs",// ESM ✅
        "require": "./index.cjs",// CJS 👎
    }
},

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

npm package.json exports filed

Package exports

https://webpack.js.org/guides/package-exports/

Node.js package.json exports field definitions

https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions

https://nodejs.org/api/packages.html#exports

The "exports" field allows defining the entry points of a package when imported by name loaded either via a node_modules lookup or a self-reference to its own name. It is supported in Node.js 12+ as an alternative to the "main" that can support defining subpath exports and conditional exports while encapsulating internal unexported modules.

Conditional Exports can also be used within "exports" to define different package entry points per environment, including whether the package is referenced via require or via import.

All paths defined in the "exports" must be relative file URLs starting with ./.

image

image

https://nodejs.org/api/packages.html#package-entry-points

https://nodejs.org/api/packages.html#subpath-exports

https://nodejs.org/api/packages.html#conditional-exports

https://nodejs.org/api/packages.html#self-referencing-a-package-using-its-name

???

https://medium.com/swlh/npm-new-package-json-exports-field-1a7d1f489ccf

https://dev.to/binjospookie/exports-in-package-json-1fl2

https://morioh.com/p/f9e6d37e27a4

https://www.cnblogs.com/taohuaya/p/15573719.html

typescript

https://stackoverflow.com/questions/73849896/expand-package-json-exports-field

https://stackoverflow.com/questions/58990498/package-json-exports-field-not-working-with-typescript

https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#packagejson-exports-imports-and-self-referencing

https://nodejs.org/api/packages.html#packages_exports

https://github.com/facebook/metro/issues/670

refs

Node.js & npm package.json exports field All In One

https://www.cnblogs.com/xgqfrms/p/17240102.html

ESM & import() & dynamic import

https://www.cnblogs.com/xgqfrms/p/16965768.html#5161668



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-03-26 13:32  xgqfrms  阅读(96)  评论(3编辑  收藏  举报