Skip to content

Commit

Permalink
Merge pull request #87 from olup/feat/optimize-package-individually
Browse files Browse the repository at this point in the history
feat(package): optimize bundle for package individually
  • Loading branch information
floydspace authored Feb 26, 2021
2 parents 65b7431 + 6c89d81 commit b88bfc8
Show file tree
Hide file tree
Showing 13 changed files with 5,622 additions and 85 deletions.
21 changes: 21 additions & 0 deletions examples/individually/hello1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as _ from 'lodash';

// modern module syntax
export async function handler(event, context, callback) {

// dependencies work as expected
console.log(_.VERSION);

// async/await also works out of the box
await new Promise((resolve) => setTimeout(resolve, 500));

const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};

callback(null, response);
}
16 changes: 16 additions & 0 deletions examples/individually/hello2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

// modern module syntax
export async function handler(event, context, callback) {
// async/await also works out of the box
await new Promise((resolve) => setTimeout(resolve, 500));

const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};

callback(null, response);
}
16 changes: 16 additions & 0 deletions examples/individually/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"main": "handler.js",
"dependencies": {
"lodash": "^4.17.4"
},
"devDependencies": {
"@types/lodash": "4.14.91",
"@types/node": "^11.13.0",
"serverless": "2.3.0",
"serverless-esbuild": "^1.5.1",
"serverless-offline": "^6.4.0"
},
"scripts": {
"start": "sls offline"
}
}
38 changes: 38 additions & 0 deletions examples/individually/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
service: serverless-example

plugins:
- serverless-esbuild
- serverless-offline

package:
individually: true

provider:
name: aws
runtime: nodejs12.x

custom:
esbuild:
packager: yarn
bundle: true
minify: true
sourcemap: false
keepNames: true
external:
- lodash


functions:
hello1:
handler: hello1.handler
events:
- http:
path: hello
method: get

hello2:
handler: hello2.handler
events:
- http:
path: hello
method: get
Loading

0 comments on commit b88bfc8

Please sign in to comment.