Browse Source

Add typescript example

master
Nicola Peduzzi 8 years ago
parent
commit
1df8259fa9
  1. 4
      README.md
  2. 3
      example/handler.js
  3. 0
      examples/babel/.babelrc
  4. 0
      examples/babel/event.json
  5. 3
      examples/babel/handler.js
  6. 0
      examples/babel/package.json
  7. 0
      examples/babel/serverless.env.yml
  8. 0
      examples/babel/serverless.yml
  9. 0
      examples/babel/webpack.config.js
  10. 5
      examples/typescript/event.json
  11. 3
      examples/typescript/handler.ts
  12. 17
      examples/typescript/package.json
  13. 15
      examples/typescript/serverless.env.yml
  14. 13
      examples/typescript/serverless.yml
  15. 13
      examples/typescript/webpack.config.js
  16. 2
      lib/run.js

4
README.md

@ -92,8 +92,8 @@ Options are:
## Example with Babel
In the `example` folder there is a Serverless project using this plugin with Babel.
To try it, from inside the example folder:
In the [`examples`](./examples) folder there is a Serverless project using this
plugin with Babel. To try it, from inside the example folder:
- `npm install` to install dependencies
- `serverless webpack run -f hello` to run the example function

3
example/handler.js

@ -1,3 +0,0 @@
export const hello = (event, context, cb) => cb(null,
{ message: 'Go Serverless Webpack v1.0! Your function executed successfully!', event }
);

0
example/.babelrc → examples/babel/.babelrc

0
example/event.json → examples/babel/event.json

3
examples/babel/handler.js

@ -0,0 +1,3 @@
export const hello = (event, context, cb) => cb(null,
{ message: 'Go Serverless Webpack (Babel) v1.0! Your function executed successfully!', event }
);

0
example/package.json → examples/babel/package.json

0
example/serverless.env.yml → examples/babel/serverless.env.yml

0
example/serverless.yml → examples/babel/serverless.yml

0
example/webpack.config.js → examples/babel/webpack.config.js

5
examples/typescript/event.json

@ -0,0 +1,5 @@
{
"key3": "value3",
"key2": "value2",
"key1": "value1"
}

3
examples/typescript/handler.ts

@ -0,0 +1,3 @@
export const hello = (event, context, cb) => cb(null,
{ message: 'Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!', event }
);

17
examples/typescript/package.json

@ -0,0 +1,17 @@
{
"name": "serverless-webpack-typescript-example",
"version": "1.0.0",
"description": "Serverless webpack example using Typescript",
"main": "handler.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Nicola Peduzzi <thenikso@gmail.com> (http://nikso.net)",
"license": "MIT",
"devDependencies": {
"serverless-webpack": "^1.0.0-beta.2",
"ts-loader": "^0.8.2",
"typescript": "^1.8.10",
"webpack": "^1.13.1"
}
}

15
examples/typescript/serverless.env.yml

@ -0,0 +1,15 @@
# This is the Serverless Environment File
#
# It contains listing of your stages and their regions
# It also manages serverless variables at 3 levels:
# - common variables: variables that apply to all stages/regions
# - stage variables: variables that apply to a specific stage
# - region variables: variables that apply to a specific region
vars:
stages:
dev:
vars:
regions:
us-east-1:
vars:

13
examples/typescript/serverless.yml

@ -0,0 +1,13 @@
service: serverless-webpack-typescript-example
# Add the serverless-webpack plugin
plugins:
- serverless-webpack
provider:
name: aws
runtime: nodejs4.3
functions:
hello:
handler: handler.hello

13
examples/typescript/webpack.config.js

@ -0,0 +1,13 @@
module.exports = {
entry: './handler.ts',
output: {
libraryTarget: 'commonjs',
path: './.webpack',
filename: 'handler.js'
},
module: {
loaders: [
{ test: /\.ts(x?)$/, loader: 'ts-loader' }
]
}
};

2
lib/run.js

@ -8,7 +8,7 @@ const utils = require('./utils');
module.exports = {
loadHandler(stats) {
const handlerFilePath = path.join(
stats.compilation.options.output.path,
path.resolve(stats.compilation.options.output.path),
stats.compilation.options.output.filename
);
utils.purgeCache(handlerFilePath);

Loading…
Cancel
Save