Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use browserify with non-npm libraries?

Tags:

npm

browserify

According to http://www.slant.co/topics/1089/viewpoints/1/~what-are-the-best-client-side-javascript-module-loaders~browserify#9 one of the downside of using Browserify is that:

Not all javascript libraries have an npm version

While it's not too hard to create npm package for an existing library, it means maintaining it when the library updates. While most libraries are now on npm, many client side specific libraries are not.

I don't have any experience with npm aside from knowing how to install an existing module. In light of that, what is the easiest/best way to browserify with client-side non-npm libraries?

Is there a way for me to declare a local Javascript file as a dependency, instead of looking it up through npm?

like image 953
Gili Avatar asked Jan 21 '15 06:01

Gili


1 Answers

You can use local modules without problems by two ways:

1.Use a relative path to a module in require:

var myModule = require('../js/my-module');

2.Use a module name, but before, you should to add it to browser property in package.json:

package.json:

...
browser: {
  my-module: './js/my-module.js'
}

app.js:

var myModule = require('my-module');
like image 94
alexmac Avatar answered Oct 21 '22 08:10

alexmac