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:

相关文章:

  • 2021-10-04
  • 2021-10-29
  • 2022-12-23
  • 2021-10-04
  • 2021-10-03
猜你喜欢
  • 2021-05-24
  • 2021-06-09
  • 2022-12-23
  • 2022-02-23
  • 2022-12-23
  • 2021-08-15
相关资源
相似解决方案