Skip to content

Instantly share code, notes, and snippets.

@millermedeiros
Created July 1, 2011 05:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save millermedeiros/1057913 to your computer and use it in GitHub Desktop.
Save millermedeiros/1057913 to your computer and use it in GitHub Desktop.
RequireJS plugin for loading files without adding the JS extension
//set location of "noext!" plugin
//(this setting should be on the top-level of your app, inside your "main.js" or HTML file)
//you could also omit this setting and just place the "ext.js" file in the `baseUrl` folder.
require({
paths : {
noext : 'path_to_plugin/noext'
}
});
//load file without appending ".js" extension
require('noext!my_awesome_script.foo', noext!other_script', function(awsum, other){
awsum.init();
other.log('yeah!');
});
/*!
* RequireJS plugin for loading files without adding the JS extension, useful for
* JSONP services and any other kind of resource that already contain a file
* extension or that shouldn't have one (like dynamic scripts).
* @author Miller Medeiros
* @version 0.3.0 (2011/10/26)
* Released under the WTFPL <http://sam.zoy.org/wtfpl/>
*/
define(function(){
var QUERY_PARAM = 'noext';
//API
return {
load : function(name, req, onLoad, config){
var url = req.toUrl(name).replace(/\.js$/, '');
req([url], function(mod){
onLoad(mod);
});
},
normalize : function(name, norm){
//append query string to avoid adding .js extension
name += (name.indexOf('?') < 0)? '?' : '&';
return name + QUERY_PARAM +'=1';
}
};
});
@millermedeiros
Copy link
Author

this plugin is related with issue 18 of RequireJS.

@millermedeiros
Copy link
Author

moved all my plugins to a new repository: https://github.com/millermedeiros/requirejs-plugins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment