jquery-require

1.0.5 • Public • Published

Simple require plugin for jQuery

Compatible to node's require and requirejs. Supports require JSON files. Supports browser cache. Firefox and Chrome debugger support (# sourceURL).

Example 1:

/js/myfile.js:
module.exports = function(arg) {
	...
}
HTML Script tag:
$.require('/js/myfile.js', function(mod) {
	mod('arguments');
});

Example 2:

/js/myfile.js:
module.exports = function(arg) {
	this.data = 'abc';
	...
}
HTML Script tag:
$.require('/js/myfile.js', function(mod) {
	var obj = new mod('arguments');
});

Example 3:

/js/myfile.js:
// anly exports works to :-)
exports = {
	data: 'abc'
}
HTML Script tag:
$.require('/js/myfile.js', function(mod) {
	console.info(mod.data); // output abc
	mod.data = 'xyz';
});

$.require('/js/myfile.js', function(mod) {
	console.info(mod.data); // output xyz
});

Example 4:

/js/myfile.js:
// anly exports works to :-)
var global_var = {data: 'abc'};
HTML Script tag:
$.require({'/js/myfile.js', exports: 'global_var'}, function(mod) {
	console.info(mod.data); // output abc
});

Example 5:

/js/myfile.js:
// anly exports works to :-)
var global_var = {data: 'abc'};
HTML Script tag:
$.require({'/js/myfile.js', exports: 'global_var', cache: false, async: false}, function(mod) {
	console.info(mod.data); // output abc
});

Package Sidebar

Install

npm i jquery-require

Weekly Downloads

5

Version

1.0.5

License

ISC

Unpacked Size

3.96 kB

Total Files

3

Last publish

Collaborators

  • comlog.gmbh