Loads the first package found in the given array.
Load the first package found from the given array., (*2)
Method | Installation |
---|---|
npm | npm install require-one --save |
component | component install robloach/require-one |
Composer | composer require require-one |
Bower | bower install require-one |
This works across CommonJS/node, AMD and with global variables for the browser., (*3)
This is an example of loading either jQuery, Zepto, or Cheerio with a CommonJS module loader, like Node.js., (*4)
``` javascript var $ = requireOne('jquery', 'zepto', 'cheerio'); // => jQuery, Zepto or Cheerio, depending on which one is available., (*5)
### AMD This is an example of loading either [jQuery](http://jquery.com), [Zepto](http://zeptojs.com), or [Cheerio](http://cheeriojs.github.io/cheerio) with an AMD module loader, like [Require.js](http://requirejs.org). ``` javascript require(['require-one'], function(requireOne) { // Retrieve the first package that is available. var $ = requireOne('jquery', 'zepto', 'cheerio'); // => jQuery, Zepto or Cheerio, depending on which one is available. // ... });
This is an example of loading either jQuery, Zepto, or Cheerio without a module loader, i.e. with the browser's global variables., (*6)
html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="path/to/require-one.js"></script>
<script>
var $ = requireOne('jquery', 'jQuery', 'zepto', 'Zepto', 'cheerio');
// => jQuery, Zepto or Cheerio, depending on which one is available.
</script>
</head>
<body>
<h1>My Sample Project</h1>
</body>
</html>
, (*7)
MIT, (*8)