作者:佩弦_秦子轩_188 | 来源:互联网 | 2023-06-11 21:59
ImtryingtobuildanodejsprojectwithNodeJStoolsforVS2015.我正在尝试使用NodeJS工具为VS2015构建一个节点js项目
I'm trying to build a node js project with NodeJS tools for VS2015.
我正在尝试使用NodeJS工具为VS2015构建一个节点js项目。
In this solution, there is a main project that has sub-projects in sub folders, i.e. each sub-folder has their own package.json with its own code and each one declares their own dependencies to other projects.
在这个解决方案中,有一个主项目在子文件夹中有子项目,即每个子文件夹都有自己的package.json,它们有自己的代码,每个子文件都声明自己对其他项目的依赖。
The problem I have is that when I do "npm install" in the main project, "npm" downloads the packages from npm registry.
我遇到的问题是,当我在主项目中执行“npm install”时,“npm”会从npm注册表中下载软件包。
I know that could use:
我知道可以使用:
"dependencies": {
"common": "file:path/to/common",
}
But this approach forces me to manually maintain two package.json files and rename it on every commit (the project is open source, on github); It is cumbersome and error prone.
但是这种方法迫使我手动维护两个package.json文件并在每次提交时重命名它(项目是开源的,在github上);它很麻烦且容易出错。
My question is: Can I configure the NodeJS tools for VS to handle two different configurations for debug and release? i.e. In a similar way that I can do it in a C# project.
我的问题是:我可以为VS配置NodeJS工具来处理调试和发布的两种不同配置吗?即以类似的方式,我可以在C#项目中做到这一点。
Something like using a package.Debug.json
file... any other approach is welcome.
像使用package.Debug.json文件...欢迎任何其他方法。
1 个解决方案
2
To do it, you can use npm-link for create a link between the package and its source code (This post about that is very interesting: npm link: developing your own npm modules without tears)
要做到这一点,你可以使用npm-link在包和它的源代码之间创建一个链接(这篇文章非常有趣:npm链接:开发你自己的npm模块而不流泪)
In your case:
在你的情况下:
- Execute
npm link
for each subproject
- 为每个子项目执行npm链接
- In main project, execute
npm link subproject1
... npm link subprojectN
- 在主项目中,执行npm link subproject1 ... npm link subprojectN
I have tested it with Visual Studio 2015 creating a solution with two projects
我已经使用Visual Studio 2015测试了它,创建了一个包含两个项目的解决方案
nodejs-projectdeps
|- nodejs-projectdeps-main
|- nodejs-projectdeps-module1
package.json for nodejs-projectdeps-main
package.json用于nodejs-projectdeps-main
{
"name": "nodejs-projectdeps-main",
"version": "0.0.0",
"description": "nodejs-projectdeps-main",
"main": "app.js",
"dependencies": {
"azure": "^0.10.6",
"nodejs-projectdeps-module1": "0.0.0"
}
}
package.json for nodejs-projectdeps-module1
package.json用于nodejs-projectdeps-module1
{
"name": "nodejs-projectdeps-module1",
"version": "0.0.0",
"description": "nodejs-projectdeps-module1",
"main": "app.js",
"dependencies": {
"dockerctl": "0.0.0"
}
}
Then I executed npm link
in the nodejs-projectdeps-module1
project folder and the result was:
然后我在nodejs-projectdeps-module1项目文件夹中执行了npm链接,结果是:
C:\Users\...\npm\node_modules\nodejs-projectdeps-module1
-> C:\src\nodejs-projectdeps\nodejs-projectdeps-module1
After I executed npm link in the nodejs-projectdeps-module1
project folder and the result was:
在nodejs-projectdeps-module1项目文件夹中执行npm链接后,结果为:
C:\src\nodejs-projectdeps-main\node_modules\nodejs-projectdeps-module1
-> C:\Users\...\npm\node_modules\nodejs-projectdeps-module1
-> C:\src\nodejs-projectdeps\nodejs-projectdeps-module1
After all, the solution in Visual Studio 2015 shows the dependencies in this way:
毕竟,Visual Studio 2015中的解决方案以这种方式显示依赖关系:
Update: The source of my test code is published on GitHub
更新:我的测试代码的源代码在GitHub上发布