项目作者: teyc

项目描述 :
Skip npm install with VSTS
高级语言: JavaScript
项目地址: git://github.com/teyc/vsts-npm-demo.git
创建时间: 2018-01-24T11:13:57Z
项目社区:https://github.com/teyc/vsts-npm-demo

开源协议:

下载


How to speed up Javascript builds on hosted VSTS agents

Synopsis

npm install can take somewhere between 8-10 minutes when there are a lot
of packages to be installed. I suspect npm install is CPU bound and network bound.

You can get around this by checking in your node_modules directory. However
this clutters up your source repository, and causes merge difficulty when node_modules
are added or removed.

Solution

Create another repository and commit your node_modules, then use git submodule
to link these two repositories together.

  1. Make sure you are using a 64bit version of nodejs.exe:

    1. $ node -p process.arch
    2. x64
  2. Create a secondary git repository For example https://github.com/teyc/vsts-npm-demo-submodule

  3. Copy the package.json and package-lock.json from the primary repository

  4. npm install to restore packages

  5. In the primary repository, add a submodule reference

    1. git submodule add https://github.com/teyc/vsts-npm-demo-submodule.git vsts-npm-demo-submodule
  6. In VSTS, enable submodule to be checked out

  7. Replace the npm install step with a Powershell step to move the directory

    1. Move-Item vsts-npm-demo-submodule/node_modules .

Potential issues

node-sass

node-sass can be very stubborn even when package-lock.json is used. It uses a different
version of binding.node depending on CPU architecture and version of nodejs that is running
on the build server.

You may have to commit every version of node_modules/node-sass/vendor/win32-x64-??/binding.node in order for your build
to work. See: https://github.com/sass/node-sass/releases

Tips and tricks

  1. Save a draft copy of the VSTS build definition, and work off there to avoid
    disrupting normal builds

  2. Disable irrelevant build steps while you are testing

  3. Git submodules refer to a particular commit. If you check in new node modules
    you must update the git submodule hash in your primary repository.

    1. git submodule init vsts-npm-demo-submodule
    2. git submodule update --remote
    3. git add vsts-npm-demo-submodule
    4. git commit -m 'Update node_modules'