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

browserify-splitter

v0.0.5

Published

Split a Browserify file into separate files that can be arbitrarily concatenated."

Downloads

14

Readme

browserify-splitter

Browserify-splitter is a Browserify plugin that allows you to split a bundle into separate files in such a way that module files can be concatenated arbtrarily.

This is currently in development. Use with caution!

Installation

npm install browserify-splitter --save

Usage

// a.js
require('lodash');
require('./c.js')
// b.js
// do something
const splitter = require('browserify-splitter');

browserify()
  .require('./a.js')
  .require('./b.js')
  .plugin(splitter, {
    writeToDir: 'public/js'
  })
  .bundle();

This will write the five following files to public/js:

  • prelude.js - Javascript that starts a bundle.
  • a.js - Module chunk file for a module.
  • b.js - Module chunk file for b module.
  • c.js - Module chunk file for c module.
  • lodash.js - Module chunk file for lodash.
  • postlude.js - Javascript that ends the bundle.

You could generate the entire bundle by concatenating all of these files together. If you didn't need b.js, you could leave it out, and the resulting bundle will still be valid. You can include or exclude any modules from the bundle as long as you include prelude at the beginning and postlude at the end.

Plugin Configuration

  • writeToDir: Required. String.
  • verbose: Boolean. Log all file writes. Defaults to false.

What's this for?

Oftentimes, developers use Browserify to precompile client JS during a build step. However, what happens when you don't know what the client needs until runtime? You have a few options:

  • Include all the JS the client possibly needs, though this may result in huge bundles.
  • Bundle only modules we know the client needs, and have the client fetch other JS as needed via async requests, though this could mean dozens of async requests.
  • Bundle on-the-fly, on request. Under many circumstances, this may not be performant, especially if you're transpiling or making other transformations.

Browserify-splitter lets you leave all the costly parts of bundle generation -- JS parsing, dependency tracing, transpiling, and transforming -- to the build step, and reap the benefits of on-the-fly bundling without sacrificing performance. By combining the plugin with browserify-extract-registy, you can export the dependency registry during your build and use it at runtime to compute dependencies based on the user's request, concatenate the appropriate modules, and give this dynamically generated bundle to the user.