Is it expected behaviour for Serverless to publish the entire project to each Lambda function it creates?

My serverless project has the following structure:

src/
    handlers/
        handler.js
        otherhandler.js
    lib/
        get-something.js
serverless.yml
package.json

Any one of my handlers may look like this:

const getSomething = require("../lib/get-something");

module.exports.getSomething = async () => {
    return getSomething();
};

I do this because I dislike having all my code in one big Lambda function.

Whenever I deploy, each Lambda function that is created contains the entire project. The entire node_modules and src folder is published along with an auto-generated file called s_getSomething.js.

Is this the intended behavior? I assume that anything other than this would webpack-like functionality of detecting dependencies, tree-shaking and so on.

Serverless can use webpack for you – put exclude/include in the serverless yaml file to specify what things to keep when packaged and what to drop. Put the general rules at the top of the serverless.yaml under package, and then override them later in individual functions using package again – my serverless.yaml looks like this:

package:
exclude:
- package.json
- serverless.yml
- README.md
- .gitignore
- .vs/**
- release_notes/**
- src/**
- resources/**
- node_modules/**

functions:
MyFunction:
package:
- /src/lambda/MyFunction.js
- /libs/requiredLibrary/requiredFile.js