Skip to content

Commit

Permalink
Merge pull request #323 from tinchoz49/tinchoz49/add-config-hook
Browse files Browse the repository at this point in the history
feat: add support for config file
  • Loading branch information
floydspace authored Jun 27, 2022
2 parents 3fd3c51 + 5ef032d commit 2c1d2ac
Show file tree
Hide file tree
Showing 9 changed files with 16,701 additions and 6 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ _Note:_ If you are using Python functions with Serverless Offline you will need

## Advanced Configuration

### Config file

Esbuild configuration can be defined by a config file.

```yml
custom:
esbuild:
config: './esbuild.config.js'
```

```js
// esbuild.config.js
module.exports = (serverless) => ({
external: [
'lodash'
],
plugins: []
})
```

### Including Extra Files

[Serverless Package Configuration](https://www.serverless.com/framework/docs/providers/aws/guide/packaging#package-configuration) will behave in the same way as native packaging. You can use `patterns`, `include` and `exclude` to include extra files into your bundles.
Expand Down
23 changes: 23 additions & 0 deletions examples/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = () => {
return {
packager: 'npm',
bundle: true,
minify: true,
sourcemap: false,
keepNames: true,
external: [
'lodash'
],
plugins: [
{
name: 'log-lodash',
setup(build) {
// test interception : log all lodash imports
build.onResolve({ filter: /^lodash$/ }, args => {
console.log(args);
});
},
}
]
};
};
20 changes: 20 additions & 0 deletions examples/config/hello1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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);
}
15 changes: 15 additions & 0 deletions examples/config/hello2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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);
}
Loading

0 comments on commit 2c1d2ac

Please sign in to comment.