amdclean
amdclean copied to clipboard
require.toUrl support?
I actually use the require.toUrl
function to get images files URLs relatively to my modules files, with the root location of images specified in my require config.
// images.js
define(["require"], function (require) {
return {
logo: require.toUrl("images/logo.png");
};
});
However, I don't know how to properly translate these require.toUrl
calls when using AMDClean to build my project: the require.toUrl
calls are kept in the optimized file, but obviously they don't work because there's no require available in the built file, and for good reason!
Any ideas how I can solve this problem? Can you please provide an example in the documentation?
The require.toUrl function is not supported in amdclean, since the purpose of amdclean is to remove the module system and emit pure javascript.
I would suggest to provide a require mock with a toUrl
function which for example returns the argument + a CDN prefix:
define("require", function() {
return {
toUrl: function(path) {
return "https://mycdn.com/"+ path;
}
};
});
Thanks for the feedback. I've experimented a little bit but I finally don't think it's a good idea to try to emulate the require.toUrl as the paths rules are fairly complicated in general... So I decided to create a "settings" module exporting some urls and I replace this module by another "settings" module in the build, which is not calling require.toUrl but use current script relative urls.