serverless/serverless-optimizer-plugin

Name: serverless-optimizer-plugin

Owner: Serverless

Description: Serverless Optimizer Plugin: Optimizers for reducing Lambda file sizes and improving their performance -

Created: 2015-12-11 11:10:39.0

Updated: 2018-05-13 08:29:06.0

Pushed: 2017-12-07 22:49:30.0

Homepage: http://www.serverless.com

Size: 47

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Serverless Optimizer Plugin

serverless

Browserifies, minifies your Serverless Node.js Functions on deployment, and more!

Reducing the file size of your AWS Lambda Functions allows AWS to provision them more quickly, speeding up the response time of your Lambdas. Smaller Lambda sizes also helps you develop faster because you can upload them faster. This Severless Plugin is absolutely recommended for every project including Lambdas with Node.js.

Note: Requires Serverless v0.5.0 or higher.

Setup
ins: [
"serverless-optimizer-plugin"

tom": {
"optimize": true

Configuration Options

Configuration options can be used by setting the optimize property to an object instead of a boolean value. The following options are available:

tom": {
"optimize": {
    "disable": true
}

tom": {
"optimize": {
    "excludeStage": ["dev", "test"]
}

tom": {
"optimize": {
    "excludeRegion": ["us-east-1"]
}

Browserify Options

Browserify options can be included as normal configuration options to the optimize object. The following options are supported:

For more information on these options, please visit the Browserify Documentaton.

Common Pitfalls

Uncaught {"errorMessage":"Cannot find module '/usr/lib/node_modules/aws-sdk/apis/metadata.json'"...

To fix this, the aws-sdk should be excluded by using the exclude Browserify option. Since the aws-sdk is always available to an AWS Lambda, it should never need to be included.

tom": {
"optimize": {
    "exclude": ["aws-sdk"]
}

ES6 with Babel and Babelify

Bundles are packaged with Browserify, and can be transformed to support ES6 features with Babelify.

Install babelify within the root context of your project:

npm install babelify --save

npm install babel-preset-es2015 --save

Add the babelify transform to s-function.json:


"name": "myfunc",
"runtime": "nodejs",
"custom": {
    "optimize": {
        "exclude": [ "aws-sdk" ],
        "transforms": [
            {
                "name": "babelify",
                "opts": {
                    "presets": [
                        "es2015"
                    ]
                }
            }
        ]
    }
}

We're currently working on adding support for Typescript. Check back for updates!


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.