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

@citation-js/browserify-disc

v1.3.5

Published

Updated fork of hughsk/disc: A tool for analyzing the module tree of a browserify bundle or node project

Downloads

36

Readme

Updated fork of hughsk/disc npm stable

Disc is a tool for analyzing the module tree of browserify project bundles. It's especially handy for catching large and/or duplicate modules which might be either bloating up your bundle or slowing down the build process.

The demo included on disc's github page is the end result of running the tool on browserify's own code base.

Installation

Disc lives on npm, so if you haven't already make sure you have node installed on your machine first.

Installing should then be as easy as:

sudo npm install -g @citation-js/browserify-disc

Or run it with npm exec (for options, see below):

npx @citation-js/browserify-disc [bundle(s)...] {options}

Command-Line Interface

Note: you'll need to build your bundle with the --full-paths flag, and pass a fully qualified (not relative) input path to browserify for disc to do its thing.

discify [bundle(s)...] {options}

Options:
  -h, --help    Displays these instructions.
  -o, --output  Output path of the bundle. Defaults to stdout.
  -O, --open    Opens disc in a new browser window automatically
  -m, --mode    the default file scale mode to display: should be
                either "count" or "size". Default: size

When you install disc globally, the discify command-line tool is made available as the quickest means of checking out your bundle. As of disc v1.0.0, this tool takes any bundled browserify script as input and spits out a standalone HTML page as output.

For example:

browserify --full-paths index.js > bundle.js
discify bundle.js > disc.html
open disc.html

You can easily chain this file into another command, or use the --open flag to open disc in your browser automatically:

browserify --full-paths index.js | discify --open

Module API

Note: you'll need to build your bundle with the fullPaths option for disc to do its thing.

require('disc')(opts)

Creates a through stream that you can pipe a bundle into, and get an HTML file in return – much like you would expect when working with the command-line tool.

So to perform the above example with Node instead of Bash:

var browserify = require('browserify')
var open = require('opener')
var disc = require('disc')
var fs = require('fs')

var input = __dirname + '/index.js'
var output = __dirname + '/disc.html'

var bundler = browserify(input, {
  fullPaths: true
})

bundler.bundle()
  .pipe(disc())
  .pipe(fs.createWriteStream(output))
  .once('close', function() {
    open(output)
  })

This method takes the following options:

  • header: HTML to include above the visualisation. Used internally to render the "Fork me on GitHub" ribbon.
  • footer: HTML to include beneath the visualisation. Used internally for the description on the demo page.
  • mode: the default file scale mode to display: one of either "count" or "size", defaulting to "size".

disc.bundle(bundles, [opts], callback)

A callback-style interface for disc: takes an array of bundles (note: the file contents and not the file names), calling callback(err, html) with either an error or the resulting standalone HTML file as arguments.

This currently mirrors how disc is currently implemented, but the stream API is a little more convenient to work with.

disc.json(bundles, callback)

Takes an array of bundle contents (as strings, or Buffers), and gathers the required data - calling callback(err, json) with either an error or the results.

Palettes

You can switch between multiple color palettes, most of which serve to highlight specific features of your bundle:

Structure Highlights

Structure Highlights

Highlights node_modules directories as green and lib directories as orange. This makes it easier to scan for "kitchen sink" modules or modules with lots of dependencies.

File Types

File Types

Highlights each file type (e.g. .js, .css, etc.) a different color. Helpful for tracking down code generated from a transform that's bloating up your bundle more than expected.

Browserify Core

Browserify Core

Highlights the automatically included and/or inserted modules that come courtesy of browserify in red. Makes it easy to quantify just how much space in your bundle is the result of shimming node's core functionality.

Original/Pastel

Nothing particularly special about these palettes – colored for legibility and aesthetics respectively.