thlorenz/browserify-shim is one of the open-source repositories TopGit tracks, currently at 928 stars, written primarily in JavaScript. 📩 Makes CommonJS incompatible files browserifyable.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
For a version compatible with the v2 API npm install [email protected] instead.
Features
The core features of browserify-shim are:
Shims non-CommonJS modules in order for them to be browserified by specifying an alias, the path to the file,
and the identifier under which the module attaches itself to the global window object.
Includes depends for shimming libraries that depend on other libraries being in the global namespace.
applies shims configured inside the dependencies of your package
Additionally, it handles the following real-world edge cases:
Modules that just declare a var foo = ... on the script level and assume it gets attached to the window object.
Since the only way they will ever be run is in the global context — "ahem, … NO?!"
Makes define and also module be undefined, in order to fix improperly-authored
libraries that need
shimming but try anyway to use AMD or CommonJS. For more info read the comment inside this
fixture
removes invalid requires, i.e. require('jquery') although 'jquery' isn't installed due to the library being
improperly published or installed incorrectly via a downloader like bower
Since browserify-shim is a proper browserify transform you can publish packages with files that need to be shimmed,
granted that you specify the shim config inside the package.json.
When browserify resolves your package it will run the browserify-shim transform and thus shim what's necessary
when generating the bundle.
browserify-shim walks upwards from each source file and uses the first "browserify-shim" configuration it finds in a package.json file. You can't shim files outside your project from your project's package. You can add multiple package.json files as long as browserify-shim can always find a package above each source file with the right configuration.
API
You Will Always
1. Install browserify-shim dependency
In most cases you want to install it as a devDependency via:
npm install -D browserify-shim
2. Register browserify-shim as a transform with browserify
The above includes ./js/vendor/jquery.js (relative to the package.json) in the bundle and exports window.$.
Additionally it exposes window.THREE as three, so you can var three = require('three'). More info
below.
Short Form vs. Long Form config
Since jquery does not depend on other shimmed modules and thus has no depends field, we used the short form to
specify its exports, however the example above is equivalent to:
You want to avoid spreading the knowledge that THREE is a global and stay consistent in how you resolve dependencies.
Additionally if THREE would ever be published to npm and you decide to install it from there,
you don't have to change any of your code since it already is requireing it properly.
b) Use aliases
You may expose files under a different name via the browser field and refer to them under that alias in the shim config:
or in a build.js script add: process.env.BROWSERIFYSHIM_DIAGNOSTICS=1 to the top.
Multi Shim Example including dependencies
Some libraries depend on other libraries to have attached their exports to the window for historical reasons :(.
(Hopefully soon we can truly say that this bad design is history.)
In this contrived example we are shimming four libraries since none of them are commonJS compatible:
x exports window.$
x-ui exports nothing since it just attaches itself to x. Therefore x-ui depends on x.
y exports window.Y and also depends on x expecting to find it on the window as $.
z exports window.zorro and depends on x and y. It expects to find x on the window as $, but y on the window as YNOT,
which is actually different than the name under which y exports itself.
We will be using the depends field in order to ensure that a dependency is included and initialized before a library
that depends on it is initialized.
Below are three examples, each showing a way to properly shim the above mentioned modules.
Note: all paths are relative to ./config/shim.js instead of the package.json.
The main difference to a) is the depends field specification. Instead it being an array of strings it expresses its dependencies as a hashmap:
key:path-to-file
value: the name under which it is expected to be attached on the window
More Examples
shim-jquery
expose-jquery
shim-jquery-external
the tests are a great resource to investigate the
different ways to configure shims and to understand how shims are applied to packages found inside the node_modules
of your package
Does thlorenz/browserify-shim have a project website?
No homepage URL was recorded for thlorenz/browserify-shim in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
Does thlorenz/browserify-shim have any tags?
TopGit's last sync did not record any GitHub topics for thlorenz/browserify-shim. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on thlorenz/browserify-shim?
The most recent commit recorded on thlorenz/browserify-shim was 6 months ago, based on the GitHub push timestamp. The repository has 84 forks — one of the better signals of community interest.
How many stars does thlorenz/browserify-shim have?
thlorenz/browserify-shim has 928 GitHub stars — refresh the page for the live number, or check github.com/thlorenz/browserify-shim. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is thlorenz/browserify-shim open source?
Yes — thlorenz/browserify-shim ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/thlorenz/browserify-shim.
Where do I read more about thlorenz/browserify-shim?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/thlorenz/browserify-shim is the definitive source.
Read full README in the tab above.
Still deciding about browserify-shim?
One click hands the question to an AI along with this page — see what it says about browserify-shim.