Skip to content

Commit bbe39d6

Browse files
authored
Merge pull request serverless-heaven#355 from serverless-heaven/webpack-4-example
Added Webpack 4 example
2 parents 7deee8d + 0e24401 commit bbe39d6

File tree

10 files changed

+15546
-0
lines changed

10 files changed

+15546
-0
lines changed

examples/babel-webpack-4/.babelrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"comments": false,
3+
"presets": [
4+
[ "env", { "node": "6.10" } ]
5+
],
6+
"plugins": [
7+
"source-map-support"
8+
]
9+
}

examples/babel-webpack-4/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
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.
2+
3+
You can also try to invoke a function locally:
4+
```
5+
serverless invoke local --function=first --path=./event.json
6+
```

examples/babel-webpack-4/event.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"key3": "value3",
3+
"key2": "value2",
4+
"key1": "value1"
5+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { App } from '../lib/App';
2+
3+
export const hello = (event, context, cb) => {
4+
context.callbackWaitsForEmptyEventLoop = false;
5+
6+
// Do not return the promise as we use the callback
7+
// This resolved promise would be be in the application library code in a real-world application and provide the results
8+
App.handleFirst(event) // eslint-disable-line promise/catch-or-return
9+
.then(result => ({
10+
statusCode: 200,
11+
headers: {
12+
'Content-Type': 'application/json;charset=utf-8'
13+
},
14+
body: JSON.stringify(result)
15+
}))
16+
.asCallback(cb);
17+
18+
return;
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { App } from '../lib/App';
2+
3+
export const hello = (event, context, cb) => {
4+
context.callbackWaitsForEmptyEventLoop = false;
5+
6+
// Do not return the promise as we use the callback
7+
// This resolved promise would be be in the application library code in a real-world application and provide the results
8+
App.handleSecond(event) // eslint-disable-line promise/catch-or-return
9+
.then(result => ({
10+
statusCode: 200,
11+
headers: {
12+
'Content-Type': 'application/json;charset=utf-8'
13+
},
14+
body: JSON.stringify(result)
15+
}))
16+
.asCallback(cb);
17+
18+
return;
19+
};

examples/babel-webpack-4/lib/App.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import BbPromise from 'bluebird';
2+
3+
const THE_MESSAGE = 'Hello from the webpack 4 sample';
4+
5+
export class App {
6+
static handleFirst(event) {
7+
const myDemoResult = {
8+
message: App.THE_MESSAGE,
9+
from: 'First lambda ;-)',
10+
event
11+
};
12+
13+
return BbPromise.resolve(myDemoResult);
14+
}
15+
16+
static handleSecond(event) {
17+
const myDemoResult = {
18+
message: THE_MESSAGE,
19+
from: 'Second lambda ;-)',
20+
event
21+
};
22+
23+
return BbPromise.resolve(myDemoResult);
24+
}
25+
}

0 commit comments

Comments
 (0)