Instead of:
<clientResources> <add name="epi-cms.widgets.base" path="addon/initialize.js" resourceType="Script" /> </clientResources>
add it as an initializer in the clientModule section:
<clientModule initializer="addon/initialize">
This way the initialize.js file doesn't get loaded at all (not visible in Firebug list of scripts and no errors on Network console). My module.config now reads:
<?xml version="1.0" encoding="utf-8"?> <module> <dojoModules> <add name="addon" path="/ClientResources/addon" /> </dojoModules> <clientModule initializer="addon/initialize"> <moduleDependencies> <add dependency="Shell" /> <add dependency="CMS" /> </moduleDependencies> </clientModule> </module>
Any ideas or pointers to documentation?
It will only be loaded when the module is first initialized. You may need to restart your site.
Here is some documentation, see the "clientModule" section: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/75/Configuration/Configuring-moduleconfig/
Then as I understand my initialize.js file will need to look like this:
define(["dojo"], function(dojo) { return dojo.declare([], { initialize: function() { // Do any custom module initialization here } }); });
which means that the 'dependency' object is missing. Of course I could add it the same way as in my original code, but then we are back to the original issue, aren't we? Shouldn't I somehow add a dependency on globalcommandregistry to my module?
No, I think the issue should be resolved by doing it the 'new' way by using an initializer.
I suppose you need to rewrite it a bit. This should be helpful: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/75/User-interface/Command-Pattern/Global-toolbar-commands-plug-in/
The first problem that I cannot come over is that nothing seems to be loaded at all. I understand that just adding the above mentioned module.config file to my site should cause load attempt that would be visible in Network tab in Firebug (initialize.js). Is this correct? It does not happen in my case.
I'm experiencing the same thing, my js file doesnt load at all when I specify it as a clientmodule. Did you solve it?
/J
Was anyone able to fix the issue where the file in the initializer of the clientModules element is never loaded? I am seeing this same issue with EPiServer 8.4.0.
File structure:
Modules.config:
(I have also tried the non-shortened path in the initializer of "Client/Widgets/ProjectPreviewLink/RegisterCommand")
RegisterCommand.js (Is not even loaded, so it should not be relevant)
Any help is appreciated.
Update: The approach mentioned (here) seems to load the JS, but it does not support adding Shell/CMS as a dependency, which seems to cause the error originally reported in this thread (unable to resolve dependency to the globalcommandregistry)
Linus,
I assume you meant I should add an initialize method to the RegisterCommand.js, but this isn't something that returns a class. It should just be running the JS in the file. It does not appear the JS is being precompiled and checked for an initialize method, meaning it would have to load the resource for it to realize there was not an initialize method. No network call is ever made in the browser for this file.
Here's how I added an initialize function anyway:
I've modified the module to have dependencies and a RunAfter, but again no luck.
Still looking for an answer. Thanks!
Edit: Please see Linus' response below for the correct answer.
CustomCommandProvider.js:
The module.config:
It still appears to be ignoring the "initializer" attribute on the <clientModule> element. Making the script execute immediately as a required resource of the base clientModule with shell/cms dependencies allowed my code to execute at the right time to avoid the "epi.globalcommandregister cannot be resolved" error.
Edit: Please see Linus' response below for the correct answer.
Thanks for the help.
I have updated the documentation to state the the client initializer should inherit from "epi/_Module": http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/8/Configuration/Configuring-moduleconfig/
Hi!
I don't think that you have to list both as dependencies since CMS takes a dependency to Shell. This is how I've specified the modules I've done:
<clientModule initializer="instantTemplates.TemplateModule"> <moduleDependencies> <add dependency="CMS" type="RunAfter" /> </moduleDependencies> </clientModule>
I get this error:
while loading the website that has this module.config file:
and this initialize.js file:
Any idea how to fix the issue? Should I use something different instead of 'epi.globalcommandregistry'?