Serverless plugin for zero-config Typescript support
- Zero-config: Works out of the box without the need to install any other compiler or plugins
- Supports ES2015 syntax + features (
export,import,async,await,Promise, ...) - Supports
sls package,sls deployandsls deploy function - Supports
sls invoke local+--watchmode - Integrates nicely with
serverless-offline
yarn add --dev serverless-plugin-typescriptAdd the following plugin to your serverless.yml:
plugins:
- serverless-plugin-typescriptSee example folder for a minimal example.
The default tsconfig.json file used by the plugin looks like this:
{
"preserveConstEnums": true,
"strictNullChecks": true,
"sourceMap": true,
"target": "es5",
"outDir": ".build",
"moduleResolution": "node",
"lib": ["es2015"],
"rootDir": "./"
}Note 1: The
outDirandrootDiroptions cannot be overwritten.
Note 2: Don't confuse the
tsconfig.jsonin this repository with the one mentioned above.
All files from package/include will be included in the final build file. See Exclude/Include
The normal Serverless deploy procedure will automatically compile with Typescript:
- Create the Serverless project with
serverless create -t aws-nodejs - Install Serverless Typescript as above
- Deploy with
serverless deploy
The plugin integrates very well with [serverless-offline][https://github.com/dherault/serverless-offline] to simulate AWS Lambda and AWS API Gateway locally.
Add the plugins to your serverless.yml file and make sure that serverless-plugin-typescript
precedes serverless-offline as the order is important:
plugins:
...
- serverless-plugin-typescript
...
- serverless-offline
...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)
Configure your service the same as mentioned above, but additionally add the serverless-dynamodb-local
plugin as follows:
plugins:
- serverless-plugin-typescript
- serverless-dynamodb-local
- serverless-offlineRun serverless offline start.
You can reduce the clutter generated by serverless-offline with --dontPrintOutput and
disable timeouts with --noTimeout.
To run your compiled functions locally you can:
$ serverless invoke local --function <function-name>Options are:
--functionor-f(required) is the name of the function to run--watch- recompile and run a function locally on source changes--pathor-p(optional) path to JSON or YAML file holding input data--dataor-d(optional) input data
Join our Slack community if you run into issues or have questions. We love talking to you!
