Created
July 1, 2011 05:17
-
-
Save millermedeiros/1057913 to your computer and use it in GitHub Desktop.
RequireJS plugin for loading files without adding the JS extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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!'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* 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'; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this plugin is related with issue 18 of RequireJS.