Reputation: 42500
I am using serverless
to package lambda implemented by typescript
. I have defined serverless.yml
and I found serverless deploy
will zip all node_modules
directory and upload to s3 bucket as lambda file. My pakcage.json has dependencies
and devDependencies
and I'd like to exclude dev deps. I know that I can do something like below:
package:
exclude:
- node_modules/**
- '!node_modules/node-fetch/**'
but I have to exclude them one by one which is not a good idea.
Another way I can think of is to run build and deploy command in a docker container where only download production dependencies. However, it is a little slow since each time I have to spinner up a container and run yarn install --only=production
command to download these dependencies.
so I am looking for a better solution to solve this issue.
Upvotes: 1
Views: 1678
Reputation: 1689
I think you can exclude dev deps like this.
package:
excludeDevDependencies: true
Spinning up docker and inistalling deps from within it is actually a better idea. Even though it takes some more time to spin it up before deployment. Some deps might have compiled binaries and if you yarn install them locally and then deploy, they might not work on a remote server.
Aside from this, have you tried parcel bundler and with serverless-simple-parcel
plugin?
Here is a sample configuration for it (goes into serverless.yml into the custom block):
custom:
parcel:
entries:
- file: src/handler.ts
target: node
outFile: handler.js
options:
publicUrl: .
Upvotes: 2