Gathering detailed insights and metrics for serverless-esbuild
Gathering detailed insights and metrics for serverless-esbuild
Gathering detailed insights and metrics for serverless-esbuild
Gathering detailed insights and metrics for serverless-esbuild
serverless-esbuild-layers
[![Test Coverage](https://api.codeclimate.com/v1/badges/e5f4215f1f3f63aad0eb/test_coverage)](https://codeclimate.com/github/beforeyoubid/serverless-esbuild-layers/test_coverage) [![Maintainability](https://api.codeclimate.com/v1/badges/e5f4215f1f3f63aad0e
serverless
[![Serverless Framework AWS Lambda AWS DynamoDB AWS API Gateway](https://github.com/serverless/serverless/assets/2752551/66a8c6a9-bc4a-4116-b139-90c12963337e)](https://serverless.com)
serverless-bundle
An extension of the serverless-webpack plugin that bundles your ES6 + TypeScript Node.js Lambda functions.
@esbuild/linux-x64
The Linux 64-bit binary for esbuild, a JavaScript bundler.
💨 A Serverless framework plugin to bundle JavaScript and TypeScript with extremely fast esbuild
npm install serverless-esbuild
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
453 Stars
379 Commits
139 Forks
6 Watching
21 Branches
71 Contributors
Updated on 22 Nov 2024
TypeScript (99.1%)
Makefile (0.7%)
JavaScript (0.13%)
Shell (0.06%)
Cumulative downloads
Total Downloads
Last day
-0.2%
45,033
Compared to previous day
Last week
6.1%
242,414
Compared to previous week
Last month
-6.5%
1,059,826
Compared to previous month
Last year
37.9%
11,681,138
Compared to previous year
16
2
26
Serverless Framework plugin for zero-config JavaScript and TypeScript code bundling using promising fast & furious esbuild
bundler and minifier
sls package
, sls deploy
, sls deploy function
Serverless Invoke Local
& serverless-offline
1# install `serverless-esbuild` and `esbuild` 2yarn add --dev serverless-esbuild esbuild 3# or 4npm install -D serverless-esbuild esbuild 5# or 6pnpm install -D serverless-esbuild esbuild
Add the following plugin to your serverless.yml
:
1plugins: 2 - serverless-esbuild
By default, no configuration is required, but you can override the default behavior via the custom.esbuild
section in the serverless.yml
file.
1custom: 2 esbuild: 3 bundle: true 4 minify: false
See example folder for some example configurations.
Option | Description | Default |
---|---|---|
Esbuild Options | This plugin can take almost any Esbuild Javascript Build Option. | Default Esbuild Options |
concurrency | The number of concurrent bundle operations to run at once. eg. 8 . NOTE: This can be memory intensive and could produce slower builds. | Infinity |
zipConcurrency | The number of concurrent zip operations to run at once. eg. 8 . NOTE: This can be memory intensive and could produce slower builds. | Infinity |
exclude | An array of dependencies to exclude from the Lambda. This is passed to the esbuild external option. Set to * to disable packaging node_modules | ['aws-sdk'] |
installExtraArgs | Optional arguments passed to npm or yarn for external dependency resolution. eg. ['--legacy-peer-deps'] for npm v7+ to use legacy peerDependency resolution behavior | [] |
keepOutputDirectory | Keeps the .esbuild output folder. Useful for debugging. | false |
nativeZip | Uses the system's zip executable to create archives. NOTE: This will produce non-deterministic archives which causes a Serverless deployment update on every deploy. | false |
outputBuildFolder | The output folder for Esbuild builds within the work folder. You will also need to manually override the watch ignore config if used. | '.build' |
outputWorkFolder | The output folder for this plugin where all the bundle preparation is done. You will also need to manually override the watch ignore config if used. | '.esbuild' |
outputFileExtension | The file extension used for the bundled output file. This will override the esbuild outExtension option | '.js' |
packagePath | Path to the package.json file for external dependency resolution. | './package.json' |
packager | Packager to use for external dependency resolution. Values: npm , yarn , pnpm | 'npm' |
packagerOptions | Extra options for packagers for external dependency resolution. | Packager Options |
watch | Watch options for serverless-offline . | Watch Options |
skipBuild | Avoid rebuilding lambda artifacts in favor of reusing previous build artifacts. | false |
skipRebuild | A boolean defining whether rebuild is avoided. Generally rebuild produces faster builds but in some context scenarios with many lambdas or low memory computer (like Github Actions) it can cause memory leaks. | false |
skipBuildExcludeFns | An array of lambda names that will always be rebuilt if skipBuild is set to true and bundling individually. This is helpful for dynamically generated functions like serverless-plugin-warmup. | [] |
stripEntryResolveExtensions | A boolean that determines if entrypoints using custom file extensions provided in the resolveExtensions ESbuild setting should be stripped of their custom extension upon packing the final bundle for that file. Example: myLambda.custom.ts would result in myLambda.js instead of myLambda.custom.js . | |
disposeContext | An option to disable the disposal of the context.(Functions can override the global disposeContext configuration by specifying their own disposeContext option in their individual configurations.) | true |
The following esbuild
options are automatically set.
Option | Default | Notes |
---|---|---|
bundle | true | Esbuild requires this for use with external |
entryPoints | N/A | Cannot be overridden |
outDir | N/A | Cannot be overridden |
platform | 'node' | Set format to esm to enable ESM support |
target | 'node18' | We dynamically set this. See Supported Runtimes |
watch | N/A | Cannot be overridden |
Option | Description | Default |
---|---|---|
scripts | A string or array of scripts to be executed, currently only supports 'scripts' for npm, pnpm and yarn | undefined |
noInstall | [Yarn only] A boolean that deactivates the install step | false |
ignoreLockfile | [Yarn only] A boolean to bypass lockfile validation, typically paired with external dependencies because we generate a new package.json with only the externalized dependencies. | false |
Option | Description | Default |
---|---|---|
pattern | An anymatch-compatible definition for the watcher to respond to | ./**/*.(js|ts) (watches all .js and .ts files) |
ignore | An anymatch-compatible definition for the watcher to ignore | ['.esbuild', 'dist', 'node_modules', '.build'] |
chokidar | Any Chokidar option | { ignoreInitial: true } |
Option | Description | Default |
---|---|---|
skipEsbuild | Set this property to true on a function definition to skip esbuild | undefined |
This plugin will automatically set the esbuild target
for the following supported Serverless runtimes:
Runtime | Target |
---|---|
nodejs20.x | node20 |
nodejs18.x | node18 |
nodejs16.x | node16 |
nodejs14.x | node14 |
nodejs12.x | node12 |
This plugin is compatible with the serverless-google-cloudfunctions plugin, and will set the runtimes accordingly.
Runtime | Target |
---|---|
nodejs20 | node20 |
nodejs18 | node18 |
nodejs16 | node16 |
nodejs14 | node14 |
nodejs12 | node12 |
This plugin is compatible with the serverless-azure-functions plugin, and will set the runtimes accordingly.
Runtime | Target |
---|---|
nodejs18 | node18 |
nodejs16 | node16 |
nodejs14 | node14 |
nodejs12 | node12 |
Please Note When using this package in conjunction with the serverless-azure-functions
plugin, the following additional configuration is required to ensure function apps are built correctly:
1package: 2 patterns: ["host.json", "**/function.json"],
If you wish to use this plugin alongside non Node functions like Python or functions with images, this plugin will automatically ignore any function which does not contain a handler or use a supported Node.js runtime.
Note: If you are using Python functions with Serverless Offline you will need to change the outputWorkFolder
and outputBuildFolder
to folder names without fullstops.
Esbuild configuration can be defined by a config file.
1custom: 2 esbuild: 3 config: './esbuild.config.js'
1// esbuild.config.js 2module.exports = (serverless) => ({ 3 external: ['lodash'], 4 plugins: [], 5});
Serverless Package Configuration will behave in the same way as native packaging. You can use patterns
, include
and exclude
to include extra files into your bundles.
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 customize this with a number of options.
1custom: 2 esbuild: 3 external: 4 - lodash 5 packager: yarn 6 packagePath: absolute/path/to/package.json 7 packagerOptions: 8 scripts: 9 - echo 'Hello World!' 10 - rm -rf node_modules 11 installExtraArgs: 12 - '--legacy-peer-deps'
To easily mark all the dependencies
in package.json
as external
, you can utilize esbuild-node-externals
plugin.
To mark one or more individual packages as external, use the following configuration:
1custom: 2 esbuild: 3 external: 4 - 'my-package-name' 5 - 'another-package-name'
Note: The Esbuild plugins API is still experimental
You can configure esbuild plugins by passing a plugins' configuration file:
1custom: 2 esbuild: 3 plugins: plugins.js
The plugins' configuration file must be a javascript file exporting an array of plugins (see examples/individually/plugins.js
for a dummy plugin example):
1let myPlugin = { 2 name: 'my-plugin', 3 setup(build) { 4 // plugin implementation 5 }, 6}; 7 8// default export should be an array of plugins 9module.exports = [myPlugin];
or a function that accepts serverless
instance and returns an array of plugins (see issue #168 for an example):
1module.exports = (serverless) => { 2 const myPlugin = { 3 name: 'my-plugin', 4 setup(build) { 5 // plugin implementation with `serverless` instance access 6 console.log('sls custom options', serverless.service.custom); 7 }, 8 }; 9 10 // an array of plugins must be returned 11 return [myPlugin]; 12};
As long as the plugin is properly installed, all regular Serverless operations sls package
, sls deploy
, sls deploy function
, sls invoke local
, sls offline
will automatically compile using serverless-esbuild
.
You can specify a custom entrypoint for ESBuild by specifying the esbuildEntrypoint
field in your function definition.
1export const myLambdaFunction = { 2 handler: '/opt/nodejs/node_modules/my_custom_extension/handler.handler', 3 esbuildEntrypoint: './handler.main', 4};
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-esbuild
precedes serverless-offline
as the order is important:
1plugins: ... 2 - serverless-esbuild 3 ... 4 - serverless-offline 5 ...
Run 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
.
1custom: 2 esbuild: 3 watch: 4 pattern: ['src/**/*.ts'] # match only typescript files in src directory 5 ignore: ['temp/**/*']
Note: When overriding the ignore pattern, remember to ignore .build
directory to avoid endless compilation.
Configure your service the same as mentioned above, but additionally add the serverless-dynamodb-local
plugin as follows:
1plugins: 2 - serverless-esbuild 3 - serverless-dynamodb-local 4 - serverless-offline
Run serverless offline start
.
This plugin supports the Serverless Invoke Local functionality and will automatically compile the selected function.
serverless-analyze-bundle-plugin
: a plugin that allow users to analyze the bundle of a lambdaInspired by serverless-plugin-typescript and serverless-webpack
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
10 commit(s) and 6 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
Found 18/27 approved changesets -- score normalized to 6
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
5 existing vulnerabilities detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More