使用gulp恢复npm包(Restoring npm packages using gulp)

我正在使用Visual Studio和TypeScript来开发Web应用程序。 有一些非常基本的东西,我不明白。

我不想将所有节点模块都签入到我的源代码控制中(它有很多文件,我不想用外部代码更新来污染我的存储库)。 所以我想在构建之前能够恢复它们。 我在网上发现gulp-install可以用来恢复软件包。 然而,gulp-install本身就是一个包,它如何被使用?

在gulp教程中,它说gulp本身应该在全球和本地安装。 我假定全局安装允许运行gulp文件,即使其余的软件包不在那里。 但其余的呢? gulp-install没有提到它应该在全球安装。 现在,我可以编写一个运行nmp install的预构建事件,但随后会安装所有软件包,所以我不明白gulp-install对...有什么好处...

所以我真正要问的是,一起使用gulp,gulp-install和source控件的正确方法是什么。

I'm using Visual Studio and TypeScript to develop a Web application. There's something pretty basic I don't understand.

I don't want to check in all the node modules into my source control (it's A LOT of files and I don't want to pollute my repository with external code updates). So I want to be able to restore them before building. I found online that gulp-install can be used to restore packages. However, gulp-install is a package itself, so how can it be used?

In the gulp tutorial it said that gulp itself should be installed both globally and locally. I assume that the global installation allows running the gulp file even when the rest of the packages are not there. But what about the rest of them? gulp-install didn't mention it should be installed globally. Now, I could write a pre-build event which runs nmp install, but then all the packages would get installed, so I don't understand what gulp-install is good for...

So what I'm asking really is what is the correct and intended way to use gulp, gulp-install and source control together.

最满意答案

“我可以编写一个运行npm install的预生成事件” - 这就是你想要的。 去gulp安装的路线确实要求所有用户已经有一个全球性的gulp安装目前。 安装gulp后,你可以在一次调用中从其他软件包管理器中获取数据,只需将npm拉进来,但是正如你所说的,你必须将gulp安装在某个地方,以便它能够直接从源代码管理中运行。 如果你愿意的话,你也可以检查当地的npm gulp install。

I don't know whether this is what the authors of gulp and/or gulp-install had in mind, but this is what I ended up doing: I installed a NuGet package called npm.js which depends on Node.js and runs npm install prior to building. The minimal Node.js version it depends on is outdated but there's a newer Node.js package which you can install and gets you node 5.3.0. If I ever need a newer node version maybe I'll ask the author to create a new package, or do it myself.

So I ended up not using gulp-install but rather install all the node packages using NuGet.

This solution works for me because NuGet is something I don't have to install - it's always there both on the development environment and on the build servers, so the solution is entirely self-contained and doesn't depend on any new installations.

更多推荐