Require One
Load the first package found from the given array.
Install
Method | Installation |
---|
npm | npm install require-one --save |
Composer | composer require require-one |
Bower | bower install require-one |
Usage
This works across CommonJS/Node, AMD and with global variables.
CommonJS/Node
var $ = requireOne(['jquery', 'cheerio']);
AMD
require(['require-one'], function(requireOne) {
var $ = requireOne(["jquery", "cheerio"]);
});
Globals
<!DOCTYPE html>
<html>
<head>
<title>My Sample Project</title>
<script type="text/javascript" src="../require-one.js"></script>
<script>
var con = requireOne(['nope', 'nopers', 'nopes', 'console']);
con.log('Hello World! Found the console?');
</script>
</head>
<body>
<h1>My Sample Project</h1>
</body>
</html>