简体   繁体   English

使用Node和Gulp设置构建服务器

[英]Setting up build server using Node and Gulp

I'm developing a front-end package and this is my environment: 我正在开发一个前端包,这是我的环境:

  • IDE: Visual Studio (I'm on Windows and we use TypeScript) IDE:Visual Studio(我在Windows上,我们使用TypeScript)
  • Package manager: NPM 包裹经理:NPM
  • Task runner: Gulp 任务选手:Gulp
  • CI: TeamCity CI:TeamCity

My problem is that I'm trying to avoid installing node and Gulp globally on my build servers (mainly because I don't want to bother managing this - installing, updating, synchronizing, etc.). 我的问题是我试图避免在我的构建服务器上全局安装节点和Gulp(主要是因为我不想打扰这个 - 安装,更新,同步等)。

So I found a NuGet package ( https://www.nuget.org/packages/Npm.js/ ) which allowed me to restore all the packages without having node installed on the machine. 所以我找到了一个N​​uGet包( https://www.nuget.org/packages/Npm.js/ ),它允许我在没有在机器上安装节点的情况下恢复所有包。 But then the problem was that the local Gulp I installed assumes there's a node.exe right next to it or in the machine's path: 但问题是我安装的本地Gulp假设它旁边有一个node.exe或者在机器的路径中:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe"  "%~dp0\..\gulp\bin\gulp.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node  "%~dp0\..\gulp\bin\gulp.js" %*
)

Now obviously this won't work since I don't have node installed on the build machine and there's no local node installation inside node_modules. 现在显然这不起作用,因为我没有在构建机器上安装节点,并且node_modules中没有本地节点安装。

So is there any way to avoid installing my build tools globally on each build server? 那么有什么办法可以避免在每个构建服务器上全局安装我的构建工具? Or were Node and Gulp intended to be installed everywhere? 或者Node和Gulp打算安装在哪里? How should then updates be maintained? 应该如何保持更新? It's not like a Visual Studio release which comes out once every few months... Or do you just ignore frequent releases of the build tools? 它不像每隔几个月发布一次的Visual Studio版本......或者您是否只是忽略了构建工具的频繁发布?

I could also add the NuGet package to the path but that (the path where node.exe is located) depends on the version of the NuGet package and requires more maintenance whenever updating it. 我还可以将NuGet包添加到路径中,但是(node.exe所在的路径)取决于NuGet包的版本,并且每次更新时都需要更多维护。 So I prefer not going this way either... 所以我不想这样做......

It's not optimal but here's what I ended up doing: I used a NuGet package for setting environment variables in MSBuild and created the following build configuration: 这不是最优的,但这是我最终做的:我使用NuGet包在MSBuild中设置环境变量并创建了以下构建配置:

<Target Name="GulpBuild">
    <SetEnvVariable Name="path" Value="%path%;..\packages\Node.js.5.3.0" />
    <Exec Command="node_modules/.bin/gulp" />
</Target>

Now when I build the solution in VS (CTRL+Shift+B) it adds the node location to the path and then calls gulp. 现在,当我在VS(CTRL + Shift + B)中构建解决方案时,它将节点位置添加到路径,然后调用gulp。 Of course I guess I could have just written the gulp command myself including the node path. 当然我想我可以自己编写gulp命令,包括节点路径。 In any case, this is of course not optimal because I need to manually update the location if I update the Node.js version, but I couldn't find any better solution. 在任何情况下,这当然不是最佳的,因为如果我更新Node.js版本我需要手动更新位置,但我找不到更好的解决方案。

At least the path configuration is defined inside the repository and does not depend on any machine configuration. 至少路径配置是在存储库内定义的,不依赖于任何机器配置。

Late here, but I think you can setup your gulp project to run with the gulp installed to node_modules. 在这里,但我认为您可以设置您的gulp项目以安装到node_modules的gulp运行。 For example, on npm start you can use the path the binary. 例如,在npm start您可以使用二进制文件的路径。

In short, can you change the project to not use the global gulp? 简而言之,您是否可以将项目更改为不使用全局gulp? It might be work looking int. 它可能是看起来工作的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM