2.2.0 • Published 3 years ago

@wolfenden/serverless-bundler v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@wolfenden/serverless-bundler Build Status npm

@wolfenden/serverless-bundler is a combination of a Serverless Framework plugin as well as a CLI that abstracts away all the packages and configuration for my serverless projects.

Its basically a combination of serverless-bundle and kcd-scripts.

It allows you to replace the following packages as well as their associated configurations with a single reference

- "eslint"
- "eslint-config-airbnb-base"
- "eslint-config-prettier"
- "eslint-plugin-import"
- "jest"
- "jest-config"
- "lint-staged"
- "prettier"
- "serverless-webpack"
- "webpack"

+ "@wolfenden/serverless-bundler"

This is heavily opinionated and is based on my preferred defaults. This project is mainly to show an example of how you could do this yourself.


Getting Started

Install the @wolfenden/serverless-bundler plugin using:

$ npm install --save-dev @wolfenden/serverless-bundler
$ yarn add @wolfenden/serverless-bundler --dev

Then add it to your serverless.yml.

plugins:
  - '@wolfenden/serverless-bundler'

package:
  individually: true

Your lambda functions will now be bundled using the bundled webpack configuration

The following scripts are also available

"scripts": {
  // formats your files using prettier
  "format": "serverless-bundler format",
  // lints your files using eslint
  "lint": "serverless-bundler lint",
  // executes your tests using jest
  "test": "serverless-bundler test"
},
"husky": {
  "hooks": {
    // runs format and lint on any commited files
    "pre-commit": "serverless-bundler pre-commit"
  }
}

Editor integration

To enabled editor integration you can add the following files to your project

// .prettierrc.js
module.exports = require('@wolfenden/serverless-bundler/prettier')
// .eslintrc.js
module.exports = require('@wolfenden/serverless-bundler/eslint')

This will ensure that your editor respects the same configuration that @wolfenden/serverless-bundler is using when runngin lint and format

Thanks

This plugin would not be possible without the amazing serverless-webpack plugin and the ideas and code from serverless-bundle and kcd-scripts.