
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
serverless-plugin-browserify
Advanced tools
Serverless v1.0 plugin that uses Browserify to bundle NodeJS Lambda functions.
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');
...
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.
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.
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
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
.
SLS_DEBUG=true
then re-run your command to output the directory. Fish Shell ex: env SLS_DEBUG=true sls browserify
FAQs
Serverless v1.0 plugin that uses Browserify to bundle NodeJS Lambda functions.
We found that serverless-plugin-browserify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.