Socket
Socket
Sign inDemoInstall

browserify-deoptimizer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browserify-deoptimizer

Transforms browserify bundles into a collection of single files


Version published
Maintainers
1
Created
Source

Split Browserify Bundles into Individual Files

Sometimes you work in browsers without //@ sourceURL or source maps. But you like using Browserify, since it's truly amazing. How will you ever debug things? With all your modules squished into one file, it's a disaster.

Enter the Browserify Deoptimizer, which will handily “de-optimize” your Browserify bundles by turning them into individual files, including files for each module you author.

Usage

You use the Browserify Deoptimizer by first creating a Browserify bundle, programmatically. Then, instead of creating a big string with bundle.bundle(), you just deoptimize it!

var browserify = require("browserify");
var deoptimize = require("browserify-deoptimizer");

var bundle = browserify();
bundle.alias("jquery", "jquery-browserify");
bundle.addEntry("start.js");

var baseDirectory = process.cwd(); // module IDs will be determined relative to this
var deoptimized = deoptimize(bundle, baseDirectory);

Your deoptimized variable will then look something like this:

{
  "browserify-prelude.js": 'var require = function (file, …',
  "node_modules/jquery-browserify/package.json": 'require.define("/node_modules/…',
  "node_modules/jquery-browserify/index.js": 'require.define("/node_modules/…',
  "browserify-aliases.js": 'require.alias("jquery-browseri…',
  "start.js": 'require.define("/start.js",fun…',
  "browserify-entry.js": 'require("/start.js");'
}

You can then use these module IDs to write out the wrapped files to the filesystem, and the appropriate <script> tags to your index.html.

Special Files

Since Browserify does some magic, we can't just create a single file for each of your modules. We need some magic files too. These are:

  • browserify-prelude.js: contains the definition of require and process, as well as any prepends with bundle.prepend. This will be the first file in the map.
  • browserify-aliases.js: Contains any calls to Browserify's require.alias to set up module aliases. This is inserted into the map after the entries for the aliased files themselves (e.g. after jquery-browserify's files). If there are no aliases, this file will not exist.
  • browserify-entry.js: Contains calls to require for all entry files in the bundle. If there are no entry files, this file will not exist.

Name

This package owes its name to r.js, the RequireJS optimizer, which turns multiple AMD modules into a single bundled file. Since this package does the opposite, I thought it'd be clever to name it a deoptimizer.

Keywords

FAQs

Package last updated on 14 Aug 2013

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc