How to specify `node_modules` from parent folder in `serverless.yml`?

Viewed 496

In serverless.yml file, how can I include the modules from parent folder?

package:
  include:
    - ../node_modules/**

but the packaged zip file doesn't include the dependencies from parent node_modules folder. I have tried the plugin: https://www.npmjs.com/package/serverless-plugin-include-dependencies but it still doesn't work. None of dependencies from parent folder is packaged.

How can I change the dependencies folder directory when packaging my application? I also want to apply excluding devDependencies logic for the parent folder.

1 Answers

I'd suggest to package your functions individually in some side script & then run the serverless deploy.

Then you can easily fine-tune your packaging process and include the node_modules from your parent, excluding the dev dependencies.

package:
  individually: true

functions:
  sample:
    package:
      artifact: ../functions/sample/deploy/sample.zip

Another small benefit on this is, if you only want to update some function you can explicitly just repackage that one and run the serverless deploy much faster.

Related