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

shimbro

v0.0.11

Published

Tiny CLI tool for managing browserify-shim fields

Downloads

8

Readme

shimbro

A tiny browserify-shim helper tool.

install

Since it's meant to be used as a command-line tool, it's easiest to install and use it globally:

npm install shimbro -g

purpose

Nobody wants to edit JSON manually! Run shimbro from your module directory to add browserify-shim fields automatically.

simple usage

The simplest use will shim a space-separated list of modules using the "global" feature.

shimbro three:THREE jquery:$ TweenLite

This will add browserify-shim as a browserify transform, and then add or update the given shims. The package.json will now contain:

  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  },
  "browserify-shim": {
    "three": "global:THREE",
    "jquery": "global:$",
    "TweenLite": "global:TweenLite"
  }

If you run it with no arguments, it will add the above with an empty object for browserify-shim.

bower dependencies

If you run with the --bower or -b argument, an interactive session will be run to try and shim out your bower dependencies. This assumes you already have a bower.json file.

So a typical usage when setting up your browserify repo might look like this:

bower init
bower install jquery threejs gsap fastclick --save
shimbro -b --ignore gsap,fastclick

This will walk through the JS files in each bower dependency, and prompt you for the alias and export of that module. Some common libraries (jquery, threejs) will already have the export object declared by default. Here's an example of the interactive session:

screen

In the above example, jQuery will be shimmed into the browserify bundle as per usual. However, since I specified global: for the THREE.js export, it will not be included in the bundle, but instead will be assumed to already be attached to the window object. This is useful to keep build times fast, and also make use of the CDN for THREE.js. The resulting package.json modifications:

  "browserify": {
    "transform": [
      "browserify-shim"
    ]
  },
  "browserify-shim": {
    "jquery": "$",
    "three": "global:THREE"
  },
  "browser": {
    "jquery": "./bower_components/jquery/dist/jquery.js"
  }

Now, in your code:

var $ = require('jquery');
var THREE = require('three');

usage/options

Usage:

shimbro [options] [globals]

Options:

  • -h, --help: show help message and quit
  • -b, --bower: detect using bower.json dependencies
  • -r, --reset: reset the browser and browserify-shim fields before adding new entries (by default, we only add to them or update existing aliases)
  • -i, --ignore: a comma-separated list of globs for bower package names to ignore
  • -o, --only: a comma-separated list of globs for bower package names; if specified, only these will be shimmed.
  • -c, --components: override the path to bower_components
  • -d, --dir: override the default base directory

advanced overrides

This project uses wiredep to determine the bower dependencies, so it will fail on bower packages that don't specify a main field (or use incorrect formatting, like a wildcard). You may see an error about a file "not being injected" -- this means that wiredep couldn't find the main JS file for that package.

To remedy this, you can specify overrides in your bower.json. This is also useful for shimming particular module(s) for large bower packages.

Here's an example of an override for GSAP. This lets us shim only TweenLite and TimelineLite, rather than the default TweenMax.

  "overrides": {
    "gsap": {
      "main": [
        "./src/uncompressed/TweenLite.js",
        "./src/uncompressed/TimelineLite.js"
      ]
    }
  }

You can then use shimbro to shim in both of these modules under different aliases.