Skip to content

Commit eeb28c2

Browse files
committed
Add examples to README
1 parent cc11034 commit eeb28c2

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

README.md

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ plugins:
2222
- serverless-plugin-typescript
2323
```
2424
25-
## Example
25+
## Configure
2626
2727
See [example folder](example) for a minimal example.
2828
29-
## `tsconfig.json`
29+
### `tsconfig.json`
3030

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

@@ -43,14 +43,78 @@ The default `tsconfig.json` file used by the plugin looks like this:
4343
}
4444
```
4545

46-
> Note 1: The `outDir` option cannot be overwritten.
46+
> Note 1: The `outDir` and `rootDir` options cannot be overwritten.
4747

4848
> Note 2: Don't confuse the [`tsconfig.json`](tsconfig.json) in this repository with the one mentioned above.
4949

50-
## Including extra files
50+
### Including extra files
5151

5252
All files from `package/include` will be included in the final build file. See [Exclude/Include](https://serverless.com/framework/docs/providers/aws/guide/packaging#exclude--include)
5353

54+
55+
## Usage
56+
57+
### Automatic compilation
58+
59+
The normal Serverless deploy procedure will automatically compile with Typescript:
60+
61+
- Create the Serverless project with `serverless create -t aws-nodejs`
62+
- Install Serverless Typescript as above
63+
- Deploy with `serverless deploy`
64+
65+
### Usage with serverless-offline
66+
67+
The plugin integrates very well with [serverless-offline][https://github.com/dherault/serverless-offline] to
68+
simulate AWS Lambda and AWS API Gateway locally.
69+
70+
Add the plugins to your `serverless.yml` file and make sure that `serverless-plugin-typescript`
71+
precedes `serverless-offline` as the order is important:
72+
```yaml
73+
plugins:
74+
...
75+
- serverless-plugin-typescript
76+
...
77+
- serverless-offline
78+
...
79+
```
80+
81+
Run `serverless offline` or `serverless offline start` to start the Lambda/API simulation.
82+
83+
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)
84+
85+
#### serverless-dynamodb-local
86+
87+
Configure your service the same as mentioned above, but additionally add the `serverless-dynamodb-local`
88+
plugin as follows:
89+
```yaml
90+
plugins:
91+
- serverless-plugin-typescript
92+
- serverless-dynamodb-local
93+
- serverless-offline
94+
```
95+
96+
Run `serverless offline start`.
97+
98+
#### Other useful options
99+
100+
You can reduce the clutter generated by `serverless-offline` with `--dontPrintOutput` and
101+
disable timeouts with `--noTimeout`.
102+
103+
### Run a function locally
104+
105+
To run your compiled functions locally you can:
106+
107+
```bash
108+
$ serverless invoke local --function <function-name>
109+
```
110+
111+
Options are:
112+
113+
- `--function` or `-f` (required) is the name of the function to run
114+
- `--watch` - recompile and run a function locally on source changes
115+
- `--path` or `-p` (optional) path to JSON or YAML file holding input data
116+
- `--data` or `-d` (optional) input data
117+
54118
## Help & Community [![Slack Status](https://slack.graph.cool/badge.svg)](https://slack.graph.cool)
55119

56120
Join our [Slack community](http://slack.graph.cool/) if you run into issues or have questions. We love talking to you!

0 commit comments

Comments
 (0)