1 | > NOTE: This plugin could cause a `maximum call stack size exceeded` error (see https://github.com/serverless/serverless/pull/3349 for fix in Serverless)
|
2 |
|
3 | # serverless-plugin-include-dependencies
|
4 |
|
5 | This is a Serverless plugin that should make your deployed functions smaller.
|
6 |
|
7 | It does this by enabling you to add your `node_modules` folder to the `exclude` list, then it individually adds each module that your handler depends on.
|
8 |
|
9 | ## Usage Example
|
10 |
|
11 | `serverless.yml`
|
12 | ```yaml
|
13 | service: sample
|
14 |
|
15 | package:
|
16 | exclude:
|
17 | - node_modules/** # no need to add this yourself, this plugin does it for you
|
18 |
|
19 | plugins:
|
20 | - serverless-plugin-include-dependencies
|
21 |
|
22 | functions:
|
23 | foo:
|
24 | handler: src/handler/foo.handler
|
25 | bar:
|
26 | handler: src/handler/bar.handler
|
27 | ```
|
28 |
|
29 | For even smaller function packages, you can also set:
|
30 |
|
31 | ```yaml
|
32 | package:
|
33 | individually: true
|
34 | ```
|
35 | But be warned: Smaller individual functions can still mean a larger overall deployment. (10 functions that are 3 MB each is more net data tranfer and storage than 1 function that is 6 MB)
|
36 |
|
37 | ## New In 2.0 - Exclusion Support
|
38 |
|
39 | Rather than including module folders (e.g. `node_modules/foo/**`, it now includes a list of actual files (e.g. `node_modules/foo/package.json`, `node_modules/foo/index.js`) and *uses the serverless package exclude* to filter these files. Excludes *must* start with `node_modules` to be considered by this plugin.
|
40 |
|
41 | The following examples would filter files of your module dependencies:
|
42 |
|
43 | - `node_modules/**/README.*`
|
44 | - `node_modules/**/test/**`
|
45 |
|
46 | These would not:
|
47 |
|
48 | - `README`
|
49 | - `**/*.txt`
|
50 |
|
51 | Even though normal matching libraries would match these rules, this library ignores them so that there's no chance of local excludes conflicting with node_modules excludes.
|
52 |
|
53 | Unless you know exactly where dependencies will be installed (e.g. several things could depend on aws-sdk) you probably want a rule more like `node_modules/**/aws-sdk/**` (which will exclude all instances of aws-sdk) and not `node_modules/aws-sdk/**` (which would only exclude a top-level aws-sdk)
|