Your function packager (for example for AWS Lambdas).
What this package does for you:
- Bundles your code using esbuild
- Generates proper package.json invidually for every function
- ZIPs your functions
The problem I faced is a simple way to compile code for AWS Lambda's and then deploy them with Terraform, I wanted to make it easier and faster hence I created this package. This might be your case aswell, but I assume there are many different use cases so feel free to create issues if you're having any problems with your use case.
npm install --save-dev funpack
yarn add -D funpack
- Add
funpack
to your package.json, for example like so:
// package.json
{
...
"funpack": {
"settings": {},
"functions": {
"myfunc1": "./src/myfunc1/index.ts",
"otherFunction": "./src/otherFunction/index.ts"
}
}
}
Settings are described under the Settings section.
- Run the
funpack
cli. For example:
{
...
"scripts": {
"prepackage": "tsc --noEmit",
"package": "funpack"
},
...
}
The funpack
cli accepts --packageJsonPath
(defaults to directory of script execution so your main package.json
) that accepts the path of the package.json
that contains the funpack config.
Each option inside settings
is optional. Below you can view what exactly is needed in the funpack object as well as which settings are available.
configSchema that represents the funpack config
For example you can use ESM with the following setup:
// package.json
{
...
"funpack": {
"settings": {
"esbuildConfigOverride": {
"format": "esm",
"target": "node16"
},
"packageFieldsToCopy": [
"type"
],
"zip": true
},
"functions": {
"main": "./src/main/index.ts"
}
}
}
Example of using custom package.json values:
{
"settings": {
"customPackageFields": {
"repository": {
"type": "git",
"url": "${YOUR_ENV_VARIABLE}"
}
}
}
}
When used together with TypeScript, esbuild will not perform type checking, so it's recommended to run tsc --noEmit
before using funpack
.