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: