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

extractify

v1.0.6

Published

Browserify plugin to extract code to be lazy loaded into separate bundles

Downloads

4

Readme

extractify

Browserify plugin to extract code to be lazy or on-demand loaded into separate bundles aka code-splitting.

build status

install

npm install extractify

how it works

Following diagram summarizes how extractify works:

alt tag

  1. dep4 module in above diagram is determined to be loaded as on-demand and should be stripped from the main bundle main.js.
  2. Therefore it will have its own stripped bundle, lazy_bundle_dep4.js which will be loaded later.
  3. The stripped bundle will also include the modules what only dep4 depends on. In this case dep5 is only used by dep4. On the other hand, dep1 module is included in main_app_bundle.js since it was already used by main.js.
  4. Optionally a map object which holds defer loaded module name and bundle name key value pairs can be injected into main entry or different .json config file soft or hard. See bundleMapOption options below

usage

You can use extractify as a browserify plugin:

browserify -p [ extractify OPTIONS ]

  // see below for OPTIONS

options

// Sampe command line OPTIONS
browserify test/files/main.js -p ['extractify' --lazy [ [ --entries [ './test/files/dep4.js' './test/files/dep6.js' ] --outfile './test/lazy_bundle/lazy_bundle.js' ] ] --bundleMapOption [ --injectSoft false --dest 'test/lazy_bundle/map.json' ] ] > test/lazy_bundle/main_bundle.js

// Sample api OPTIONS
{
  bundleMapOption: {
    injectSoft: false,
    dest: 'lazy_bundle/map.json'
  },
  lazy: [
    {
      entries: [
        './files/dep4.js'
      ],
      outfile: './lazy_bundle/lazy_bundle_dep4.js'
    }
  ]
}
  • bundleMapOption: optional property that instructs how the map object will be injected into source or written into file system
    • injectSoft: instructs how the map object will be injected. If it is true, it will be written to the dest file [default: true]
    • dest: optional location of map destination .json map file which holds module name and bundle name key value pairs
  • lazy: holds the lazy entry and output files definition.
    • entries: array of the entry module names to build stripped lazy bundle
    • outfile: name of the stripped lazy bundle

api plugin example

var browserify = require('browserify');
var fs = require('fs');
var b = browserify(['./files/main.js'], {
    basedir: __dirname
});
b.plugin('extractify', {
  lazy: [
    {
      entries: [
        './files/dep4.js',
        './files/dep6.js'
      ],
      outfile: './bundles/lazy_bundle.js'
    }
  ]
});
b.bundle().pipe(fs.createWriteStream('./bundles/main_app.js'))

events

b.on('lazyWritten', function (outfile) {})

Emits with lazy bundle outfile right after the splitted bundle written into the file system

b.on('lazyStream', function (stream) {})

Each splitted bundles will emits stream before written into filesystem. The outfile name is available as stream.file.

license

MIT