How to use private dependencies

Sometimes you need to add more functionality than Serverless has by default. You can create a private plugin for it (Consider making it public after testing, help the community :) ). Just create a new folder with the name of the plugin. We use how-to-use-private-dependencies as an example name.

 

git init
git remote add origin YOU_PRIVATE_REPO_ADDRESS
npm init

 

npm will walk you through a bunch of questions. Make sure you specify index.js as an entry point. After that we need to use Serverless to create a template for our plugin.

serverless create --template plugin

You can check out newly created index.js. More details about the structure of the file can be found here

 

Then, just push the changes to the repo.

git add .
git commit -m "first"
git tag -a v1.0 -m "version 1.0"
git push origin v1.0

It is very important to add a tag to your repository and keep tagging new releases. In case you don't do it, any changes to the repository master branch can potentially break all the projects that depend on the project.

Then, you can open any Serverless project and add newly created plugin to plugins list.

plugins:
  - how-to-use-private-dependencies

 

In order for that to work, you have to do the npm install from the private repo.

npm install --save-dev git+ssh://git@git-host.com:user/serverless_how-to-use-private-dependencies.git#v1.0

Now, you can check if the plugin exists by running:

serverless

New command welcome should appear in the list of commands. Try running:

serverless welcome -m "hello world"

to test if the plugin works.