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

broaderify

v2.0.0

Published

All-around transform for Browserify

Downloads

17

Readme

broaderify

NPM version Build Status Coverage percentage

All-around transform for Browserify.

Installation

npm install broaderify

Motivation

The initial motivation comes from the need to inject dependencies into modules that don't import them by themselves - bootstrap 3 for example, and by the flawed approach used by browserify-shim to deal with that problem:

  • Pollution of the global scope since browserify-shim is unable to inject dependency in the scope of the dependent module
  • Configuration in package.json only - a thing that makes browserify-shim stands apart from every other Browserify transforms and implies having Browserify configuration splits in two different places just because of browserify-shim

Broaderify adopts a very similar strategy to webpack loaders: it allows full source transformation control based on module name filtering.

Usage

import * as Browserify from "browserify";
import broaderify from "broaderify";

Browserify()
    .transform(broaderify, {
        loaders: [{
            filter: /foo.js/,
            worker: (module, content, done) => {
                // do whatever you want with content
                done(content);
            }
        }]
    })
    .add('index.js');

API

Read the documentation for more information.

Configuration options:

  • global: A boolean indicating if broaderify should be applied to node_modules modules.
  • loaders: An array of loaders that will be tested against each module passed to broaderify. Each loader must be an object with at least the following properties:
    • filter: A RegExp instance that will be tested against the path of the module to determine if it should be transformed.
    • worker: A function that will be called for each module that needs transformation, with the following arguments:
      • module: The path of the module.
      • content: The content of the module - i.e. the source.
      • done: A function that needs to be called with the transformed source once the transformation is done.

Recipes

Injecting jQuery into Bootstrap 3

import * as Browserify from "browserify";
import broaderify from "broaderify";

let bundle = browserify()
    .transform(broaderify, {
        global: true,
        loaders: [{
            filter: /node_modules\/bootstrap\/js\/(.*).js/,
            worker: (module, content, done) => {
                content = 'var jQuery = require(\'jquery\');' + content;

                done(content);
            }
        }]
    })
    .add('index.js');

Injecting jQuery into a jQuery plugin

Let's take parallax.js jQuery plugin as an example. It is a very good example because it makes the explicit assumption that jQuery is part of the window object:

import * as Browserify from "browserify";
import broaderify from "broaderify";

let bundle = browserify()
    .transform(broaderify, {
        global: true,
        loaders: [{
            filter: /node_modules\/parallax-js\/source\/jquery.parallax.js/,
            worker: (module, content, done) => {
                content = content.replace('window.jQuery || window.Zepto', 'jQuery');
                content = 'var jQuery = require(\'jquery\');' + content;

                done(content);
            }
        }]
    })
    .add('index.js');

Contributing

  • Fork the main repository
  • Code
  • Implement tests using tape
  • Issue a pull request keeping in mind that all pull requests must reference an issue in the issue queue

License

Apache-2.0 © Eric MORAND