我已经完成npm install ./pathtolocalfolder --save
。
我的package.json
有一个名为file: ../pathtolocalfolder
的依赖项。
如何将文件夹导入项目中?
npm无法解析./node_modules/folder
或folder
。
答案 0 :(得分:0)
我刚刚测试了一下,效果很好。
您甚至不需要使用npm install ./testmodule --save
,但是您的模块必须具有package.json
主要./package.json与testmodule的引用
{
"name": "npmtest",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"testmodule": "file:testmodule"
}
}
主要./app.js
var testmod = require('testmodule');
testmod.run();
./ testmodule / package.json
{
"name": "testmodule",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
./ testmodule / index.js
exports.run = function() { console.log('testmodule'); }