esbuild bundler and minifier
sls deploy function
sls invoke local
ES2017, so the final bundle will be supported by all AWS Lambda Node.js runtimes. If you still using an old lambda runtime and have to respect it you can play with esbuild
yarn add --dev serverless-esbuild # or npm install -D serverless-esbuild
Add the following plugin to your
plugins: - serverless-esbuild
By default, no configuration is required, but you can change esbuild behavior in custom
esbuild section in
custom: esbuild: bundle: true minify: false
Check esbuild documentation for the full list of available options. Note that some options like
outdir cannot be overwritten.
The package specified in the
exclude option is passed to esbuild as
external, but it is not included in the function bundle either. The default value for this option is
See example folder for a minimal example.
All files from
package/patterns will be included in the final build file. See Patterns.
Include/exclude is deprecated, but still supported.
Packages that are marked as
external and exist in the package.json's
dependencies will be installed and included with your build under
node_modules. You can configure how these are installed:
custom: esbuild: packager: yarn # optional - npm or yarn, default is npm packagePath: absolute/path/to/package.json # optional - by default it looks for a package.json in the working directory
Note that the plugins API is still experimental : see the documentation page
You can configure esbuild plugins by passing a plugins' configuration file:
custom: esbuild: plugins: plugins.js
examples/individually/plugins.js for a dummy plugin example)
The normal Serverless deploy procedure will automatically compile with
serverless create -t aws-nodejs
The plugin integrates very well with serverless-offline to simulate AWS Lambda and AWS API Gateway locally.
Add the plugins to your
serverless.yml file and make sure that
serverless-offline as the order is important:
plugins: ... - serverless-esbuild ... - serverless-offline ...
serverless offline or
serverless offline start to start the Lambda/API simulation.
In comparison to
serverless offline, the
start command will fire an
init and a
end lifecycle hook which is needed for
serverless-offline and e.g.
serverless-dynamodb-local to switch off resources (see below)
Automatic compilation is available while using the plugin with
serverless-offline. Following are the default configuration:
You can override the defaults by using
watch option in serverless esbuild config. Both options take anymatch-compatible definition
custom: esbuild: watch: pattern: ['src/**/*.ts'] # match only typescript files in src directory ignore: ['temp/**/*']
Note: When overriding ignore pattern, remember to ignore
.build directory to avoid endless compilation.
Configure your service the same as mentioned above, but additionally add the
plugin as follows:
plugins: - serverless-esbuild - serverless-dynamodb-local - serverless-offline
serverless offline start.
To run your compiled functions locally you can:
$ serverless invoke local --function <function-name>
-f(required) is the name of the function to run
-p(optional) path to JSON or YAML file holding input data
-d(optional) input data
Latest commit b2f54ec on Sep 24, 2017