I am building an application on Pi-engine (a php application engine based on zend framework 2).
In my application the javascript file path depends on the application name, while the application name is pickded by installer.
For example the url of require.js would be:
http://my.site.name/asset/module-{module_name}/script/js/require.js
module_name changes according to what name the application is given.
I know I can put path in 'data-main' attribute in backend like:
<script data-main="/asset/module-{module_name}/script/" src="/asset/module-{module_name}/script/js/require.js"></script>
But I want to know is there any way to set baseurl dynamicly using javascript so that I don't need to touch the backend.
http://requirejs.org/docs/api.html#config
Also, you can define the config object as the global variable require before require.js is loaded, and have the values applied automatically. This example specifies some dependencies to load as soon as require.js defines require():
<script>
var require = {
baseUrl: generateBaseUrl()
};
</script>
<script src="scripts/require.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With