Wednesday, 28 August 2013

requirejs global config in main html file does not work after optimize

requirejs global config in main html file does not work after optimize

I need to add option to configure widget in html file where it will be
used. I found that there is require.js build in mechanism described here:
http://requirejs.org/docs/api.html#config
I managed to make it work in my project but its not working in minified
version.
In HTML file I have:
<script >
var require = {
config: {
'models/ad': {
'myKey':'myValue1'
}
}
}
</script>
And in my ad.js I have:
define(['backbone', 'module'], function(Backbone, module) {
console.log(module.config().myKey);
var BbModel = Backbone.Model.extend({
// Some backbone code
});
return BbModel;
});
Everything works fine (variable is passed from html to module) but if I
optimize:
r.js -o build.js
it just stops working, module.config().myKey returns nothing.
It works for optimized wersion if I add config: { 'models/ad': {
'myKey':'myValue1' } in main.js require.config(...);
Due to project requirements I must set variable in html file.
Do you have any idea what it can be?

No comments:

Post a Comment