asotog
10/8/2014 - 7:47 PM

optional requirejs moduling

optional requirejs moduling

(function(factory) {
	if (typeof exports === 'object') {
		// Node/CommonJS
		factory(require('jquery'));
	} else if (typeof define === 'function' && define.amd) {
		// AMD
		define([ 'jquery' ], factory);
	} else {
		// Browser globals
		factory(jQuery);
	}
}(function($) {
	console.log('In test2.')
}));
(function(factory) {
	if (typeof exports === 'object') {
		// Node/CommonJS
		factory();
	} else if (typeof define === 'function' && define.amd) {
		// AMD
		define([], factory);
	} else {
		// Browser globals
		factory();
	}
}(function() {
	console.log('In test1.');
}));
<!doctype html>
<html lang="en">
<head>
	<title>Test Execute Order</title>
</head>

<body>
	<script src="//requirejs.org/docs/release/1.0.1/minified/require.js"></script>
	<script>
		require.config({
			paths: {
				'jquery': '//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min'
			}
		});
	</script>
	<script>
		require(['scripts/test2'], function(){
			console.log('In index2.')
		});
	</script>
</body>
<!doctype html>
<html lang="en">
<head>
	<title>Test Execute Order</title>
</head>

<body>
	<script src="//requirejs.org/docs/release/1.0.1/minified/require.js"></script>
	<script>
		require.config({
			paths: {
				'jquery': '//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min'
			}
		});
	</script>
	<script>
		require(['scripts/test1'], function(){
			console.log('In index1.')
		});
	</script>
</body>