Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Webpack 4 example #355

Merged
merged 1 commit into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/babel-webpack-4/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"comments": false,
"presets": [
[ "env", { "node": "6.10" } ]
],
"plugins": [
"source-map-support"
]
}
6 changes: 6 additions & 0 deletions examples/babel-webpack-4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This is the default babel webpack-4 example to look at, because only dynamic entry point resolution lets you use Serverless completely. Individual packaging with a per-function dependency optimization is only available with that approach.

You can also try to invoke a function locally:
```
serverless invoke local --function=first --path=./event.json
```
5 changes: 5 additions & 0 deletions examples/babel-webpack-4/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"key3": "value3",
"key2": "value2",
"key1": "value1"
}
19 changes: 19 additions & 0 deletions examples/babel-webpack-4/handlers/first.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { App } from '../lib/App';

export const hello = (event, context, cb) => {
context.callbackWaitsForEmptyEventLoop = false;

// Do not return the promise as we use the callback
// This resolved promise would be be in the application library code in a real-world application and provide the results
App.handleFirst(event) // eslint-disable-line promise/catch-or-return
.then(result => ({
statusCode: 200,
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(result)
}))
.asCallback(cb);

return;
};
19 changes: 19 additions & 0 deletions examples/babel-webpack-4/handlers/second.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { App } from '../lib/App';

export const hello = (event, context, cb) => {
context.callbackWaitsForEmptyEventLoop = false;

// Do not return the promise as we use the callback
// This resolved promise would be be in the application library code in a real-world application and provide the results
App.handleSecond(event) // eslint-disable-line promise/catch-or-return
.then(result => ({
statusCode: 200,
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(result)
}))
.asCallback(cb);

return;
};
25 changes: 25 additions & 0 deletions examples/babel-webpack-4/lib/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import BbPromise from 'bluebird';

const THE_MESSAGE = 'Hello from the webpack 4 sample';

export class App {
static handleFirst(event) {
const myDemoResult = {
message: App.THE_MESSAGE,
from: 'First lambda ;-)',
event
};

return BbPromise.resolve(myDemoResult);
}

static handleSecond(event) {
const myDemoResult = {
message: THE_MESSAGE,
from: 'Second lambda ;-)',
event
};

return BbPromise.resolve(myDemoResult);
}
}
Loading