【发布时间】:2017-12-17 22:15:22
【问题描述】:
我正在使用 the serverless framework 编写一些 nodejs 函数。 package.json 文件需要一些依赖项:
{
"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"
}
}
node-modules 目录的大小几乎是 50mb:
# du -smc node_modules
47 node_modules
47 total
部署时间超过 35 秒,压缩包大小约为 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
这有点低效 - 我只更改一个文件,但只要我做最轻微的更改,我就必须打包所有未更改的依赖项。
知道如何减小 zip 大小(可能删除 devDependencies),或者只上传更改的文件吗?
【问题讨论】:
标签: node.js npm dependencies aws-lambda serverless-framework