nodejs package.json中的exports


test/package.json

{
  "name": "test",
  "main": "index.js",
  "exports": {
    ".": {
      "require": "./index.js"
    },
    "./a": "./functions/a.js",
    "./b": "./functions/b.js",
    "./f/": "./functions/"
  }

在另一个模块中使用test模块:
demo/package.json

{
  "name": "demo",
  "main": "index.js",
  "dependencies": {
    "test": "file:../test"
  }
}

demo/index.js

const index = require('test')
index();

const a = require("test/a");
const b = require("test/b");
a();
b();

const a2 = require("test/f/a");
const b2 = require("test/f/b");
a2();
b2();

See also:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM