Exclude everything in the build except one folder Serverless Patterns

I am working on a serverless project. what I want to achieve or want to know if it is possible or not is that when I run sls package i want the serverless to exclude every file/folder in the root directory except for one folder.

I have tried multiple ways to do it using patterns in serverless file but nothing worked.

package: #This didn't not work
  patterns:
    - '!./**'
    - './dist/**'


package: # This didn't work
  patterns:
    - '!.*/**'
    - './dist/**'

Am I missing something? Because I was able to exclude particular folders if I define them explicitly. But I was unable to exclude the entire root directory using wild card characters.

package: # This works and excludes constant folder
  patterns:
    - '!./constants/**'

I know I can achieve it by making a script. But I want to know if it can be done via the serverless framework by simply defining the patterns.

1 Like