How to include npm module AND it's dependencies?

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

What is the best currently way of doing this?

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.

Thank you @buggy! I’ve done a quick test here and it seems to be working.

I thought sls invoke test wouldn’t run with serverless-mocha-plugin outside of the service folder.