Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: AMD Loader Module Scoping
What is the scope of a module loaded through the "Liferay-JS-Config" flag in bnd.bnd and code like this....
Loader.addModule({
dependencies: [],
name: 'jquery',
path: MODULE_PATH + '/js/jquery-2.2.3.js'
});
.....does that now create a 'jquery' module that all other bundles (Liferay modules) can reference/require? (i.e. globally scoped)
or is that 'jquery' module only available to other "require" operations within the same bundle (ie the one that contained the code above)?
Loader.addModule({
dependencies: [],
name: 'jquery',
path: MODULE_PATH + '/js/jquery-2.2.3.js'
});
.....does that now create a 'jquery' module that all other bundles (Liferay modules) can reference/require? (i.e. globally scoped)
or is that 'jquery' module only available to other "require" operations within the same bundle (ie the one that contained the code above)?
Hey Michael!
Yes, the Loader.addModule should create a globally available module. After that, everyone should be able to require the jquery module.
Are you seeing any issue with it?
Yes, the Loader.addModule should create a globally available module. After that, everyone should be able to require the jquery module.
Are you seeing any issue with it?
No issues--but I was just working on some stuff and my approach was going to have change a bit if they weren't globally scoped. So thats good news in the end to me 
Thanks
Thanks
Hola para la versión 7.2 de liferay ya no se puede hacer el Loader.addModule para esta versión como se debe utilizar o que función es el reemplazo, gracias.
Loader.addModule does not longer exist and there's no replacement for it. That is because all JS module resolution is now done in the server side so it would be quite inefficient (and probably impossible in some scenarios) to support Loader.addModule.
The alternatives depend on what you are trying to achieve. The most direct one is to simply deploy the module you were adding with Loader.addModule to the server (in a shared bundle JAR) and then consume it from others with the imports feature.
For example, this project implements shared bundles that deploy react, redux, etc. and two portlets that consume them -> https://github.com/izaera/liferay-js-toolkit-showcase/tree/react
The alternatives depend on what you are trying to achieve. The most direct one is to simply deploy the module you were adding with Loader.addModule to the server (in a shared bundle JAR) and then consume it from others with the imports feature.
For example, this project implements shared bundles that deploy react, redux, etc. and two portlets that consume them -> https://github.com/izaera/liferay-js-toolkit-showcase/tree/react