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-plugin-browserify

v1.1.3

Published

Serverless v1.0 plugin that uses Browserify to bundle NodeJS Lambda functions.

Downloads

173

Readme

Serverless Browserify Plugin

serverless

A Serverless v1.0 plugin that uses Browserify to bundle your NodeJS Lambda functions.

Why? Lambda's with smaller code start and run faster. Lambda also has an account wide deployment package size limit.

aws-sdk-js now officially supports browserify. Read more about why this kicks ass on my blog.

With the example package.json and javascript code below, the default packaging for NodeJs lambdas in Serverless produces a zip file that is 11.3 MB, because it blindly includes all of node_modules in the zip.

This plugin with 2 lines of configuration produces a zip file that is 400KB!

...
  "dependencies": {
    "aws-sdk": "^2.6.12",
    "moment": "^2.15.2",
    "request": "^2.75.0",
    "rxjs": "^5.0.0-rc.1"
  },
...
const Rx      = require('rxjs/Rx');
const request = require('request');
...

Install

From your serverless project run:

npm install serverless-plugin-browserify --save-dev

Add the plugin to your serverless.yml file and set package.individually to true:

plugins:
  - serverless-plugin-browserify
package:
  individually: true

package.individually is required because it makes configuration more straight forward, and if you are not packaging individually size is not a concern of yours in the 1st place.

Configure

For most use cases you should NOT need to do any configuration. If you are a code ninja, read on.

The base config for browserify is read from the custom.browserify section of serverless.yml. All browserify options are supported (most are auto configured by this plugin). This plugin adds one special option disable which if true will bypass this plugin.

The base config can be over-ridden on a function by function basis. Again custom.browserify is not required and should not even need to be defined in most cases.

custom:
  browserify:
    #any option defined in https://github.com/substack/node-browserify#browserifyfiles--opts

functions:
    usersGet:
      name: ${self:provider.stage}-${self:service}-pageGet
      description: get user
      handler: users/handler.hello      
      browserify:
        noParse:
          - ./someBig.json  #browserify can't optimize json, will take long time to parse for nothing      

Note: package.include can be used with this plugin. All other options can be handled by leveraging browserify options in your serverless.yml custom browserify section.

Usage

When this plugin is enabled, and package.individually is true, running serverless deploy and serverless deploy -f <funcName> will automatically browserify your node lambda code.

If you want to see output of bundled file or zip simply set SLS_DEBUG. Ex (using Fish Shell): env SLS_DEBUG=true sls deploy function -v -f usersGet

Also check out the examples directory

Bundle only

Run serverless browserify -f <functionName>. You can optionally dictate where the bundling output dir is by using the -o flag. Ex: sls browserify -o /tmp/test -f pageUpdate.

FAQ

  • Should I use Webpack instead of this plugin? I prefer Browserify over webpack because I have found it supports more modules, optimizes better, and requires less configuration.
  • Why is UglifyJS not built-in? No ES6 support. Issue been open since 2014.
  • My code is not bundling correctly The bundled code is always stored in a tmp dir on your computer. Set SLS_DEBUG=true then re-run your command to output the directory. Fish Shell ex: env SLS_DEBUG=true sls browserify