npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-optimizer-plugin

v2.5.1

Published

Serverless Optimizer Plugin - Significantly reduces Lambda file size and improves performance

Downloads

3,674

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

  • Install via npm in the root of your Serverless Project:
npm install serverless-optimizer-plugin --save
  • Add the plugin to the plugins array in your Serverless Project's s-project.json, like this:
plugins: [
    "serverless-optimizer-plugin"
]
  • In the custom property of your s-function.json add an optimize property.
"custom": {
    "optimize": true
}
  • If you rely on the aws-sdk, be sure to read the Common Pitfalls section.

  • All done!

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:

  • disable - When set to true, this will disable optimizer. This is effectively the same as setting the optimize property to false, but it does not require the deletion of any other configuration values within the optimize object. This is a good option for temporarily disabling while debugging.
"custom": {
    "optimize": {
        "disable": true
    }
}
  • excludeStage - When set to a string or [string], optimizer will be disabled for the specified stage(s). This is beneficial if you do not want optimizer to run on a specific stage to aid in debugging.
"custom": {
    "optimize": {
        "excludeStage": ["dev", "test"]
    }
}
  • excludeRegion - When set to a string or [string], optimizer will be disabled for the specified region(s).
"custom": {
    "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:

  • handlerExt
  • includePaths
  • requires
  • plugins
  • transforms
  • exclude
  • ignore
  • extensions

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

Common Pitfalls

  • aws-sdk does not play well with Browserify. If the aws-sdk is used anywhere in your code, even if it is not within node_modules or package.json, you may receive an error similar to:

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.

"custom": {
    "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!