I am writing a few nodejs functions using the serverless framework. The package.json file requires a few dependencies:
{
"name": "adam-test-sls",
"version": "0.1.0",
"description": "Test package to play with sls/lambda",
"main": "handler.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Adam Matan <adam@binaris.com>",
"license": "UNLICENSED",
"dependencies": {
"aws-sdk": ">= 2.0.9",
"json": "^9.0.6",
"underscore": "^1.8.3",
"uuid": "^3.1.0"
},
"devDependencies": {
"eslint": "^4.2.0",
"eslint-config-airbnb": "^15.0.2",
"eslint-config-airbnb-base": "^11.2.0",
"eslint-plugin-import": "^2.7.0"
}
}
The size of the node-modules directory is almost 50mb:
# du -smc node_modules
47 node_modules
47 total
Deployment time is more than 35 seconds, given a zip size of ~9.5MB:
# time serverless deploy function --function hello -v
Serverless: Packaging function: hello...
Serverless: Uploading function: hello (9.46 MB)...
Serverless: Successfully deployed function: hello
serverless deploy function --function hello -v 4.28s user 1.15s system 15% cpu 35.165 total
This is somewhat inefficient - I only change one file, but I have to pack all the unchanged dependencies whenever I make the slightest change.
Any idea how to reduce the zip size (perhaps removing devDependencies), or upload only the changed file?