prismagraphql/serverless-plugin-typescript

Name: serverless-plugin-typescript

Owner: Prisma

Description: Serverless plugin for zero-config Typescript support

Created: 2017-04-17 13:26:19.0

Updated: 2018-05-24 00:37:41.0

Pushed: 2018-05-18 21:52:25.0

Homepage:

Size: 431

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

serverless-plugin-typescript

serverless npm version Build Status

Serverless plugin for zero-config Typescript support

Features
Install
 add --dev serverless-plugin-typescript

Add the following plugin to your serverless.yml:

ins:
serverless-plugin-typescript
Configure

See example folder for a minimal example.

tsconfig.json

The default tsconfig.json file used by the plugin looks like this:


ompilerOptions": {
"preserveConstEnums": true,
"strictNullChecks": true,
"sourceMap": true,
"target": "es5",
"outDir": ".build",
"moduleResolution": "node",
"lib": ["es2015"],
"rootDir": "./"


Note 1: The outDir and rootDir options cannot be overwritten.

Note 2: Don't confuse the tsconfig.json in this repository with the one mentioned above.

Including extra files

All files from package/include will be included in the final build file. See Exclude/Include

Usage
Google Cloud Functions

When using with Google Cloud Functions via the serverless-google-cloudfunctions plugin, you simply have to provide a main field in your package.json:


 ...
ain": "handler.js",
 ..

And this plugin will automatically compile your typescript correctly. Note that the field must refer to the compiled file name, namely, ending with a .js extension.

If a main field was not found, then this plugin will use index.js. Before compilation begins, it will check to see that the file indicated exists with a .ts extension before actually trying to compile it.

Automatic compilation

The normal Serverless deploy procedure will automatically compile with Typescript:

Usage with serverless-offline

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-plugin-typescript precedes serverless-offline as the order is important:

ugins:
...
- 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)

serverless-dynamodb-local

Configure your service the same as mentioned above, but additionally add the serverless-dynamodb-local plugin as follows:

ugins:
- serverless-plugin-typescript
- serverless-dynamodb-local
- serverless-offline

Run serverless offline start.

Other useful options

You can reduce the clutter generated by serverless-offline with --dontPrintOutput and disable timeouts with --noTimeout.

Run a function locally

To run your compiled functions locally you can:

rverless invoke local --function <function-name>

Options are:

Enabling source-maps

You can easily enable support for source-maps (making stacktraces easier to read) by installing and using the following plugin:

 add --dev source-map-support
s
nside of your function
rt 'source-map-support/register'

If you are using webpack (most likely). Add devtool: 'source-map' to webpack.config.js:

le.exports = {
.. snip ....
vtool: 'source-map',
.. snip ....


Help & Community Slack Status

Join our Slack community if you run into issues or have questions. We love talking to you!


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.