bitten
bitten

Reputation: 2543

How to include folder but excluding some files inside that folder when packaging for serverless?

I want to include node_modules, but exclude the .bin dir, and the .cache and .yarn-integrity files since they take up space on the lambda.

        exclude:
            - ./**
            - '!node_modules/**'
            - node_modules/.cache
            - node_modules/.bin
            - node_modules/.yarn-integrity

Like wise, I would like to include the 'server' folder, but exclude the tests and eslint config files:

        exclude:
            - ./**
            - '!server/**'
            - server/**/*.test.js
            - server/.eslintrc.js

But neither work, and the files are not excluded. What's the correct way to do this?

Upvotes: 3

Views: 1724

Answers (1)

Jon Medwig
Jon Medwig

Reputation: 631

You can include the node_modules/ dir while excluding the node_modules/.bin dir like this:

package:
   exclude:
     - node_modules/.bin/**

By default only these directories are excluded:

.git/**
.gitignore
.DS_Store
npm-debug.log
.serverless/**
.serverless_plugins/**

So you do not need to specify that node_modules/ and server/ are to be included - they will be be default. Just specify which sub-directories inside them you want to exclude.

Source: https://serverless.com/framework/docs/providers/aws/guide/packaging/

Upvotes: 2

Related Questions