Example:
I want to include mongoose and it’s dependencies but exclude serverless-mocha-plugin and it’s unnecessary dependencies.
In the following example I would still be packaging all the serverless-mocha-plugin dependencies that won’t be used.
package:
exclude:
- node_modules/serverless-mocha-plugin
The best solution seems to be putting dev dependencies into a packages.json/node_modules in your project root and runtime dependencies into a package.json/node_modules in your service folder. I wrote a blog post about Keeping Dev Dependencies Out Of Your Serverless Package a few weeks ago.
You could also look at using the serverless-webpack plugin. With tree shaking this will get your package even smaller.