I've decided to implement RequireJs within MS CRM, but I'm unsure of how to integrate it with my TypeScript files.
Each form in CRM currently has its own TypeScript file structured similar to this:
// File Path .\_Contoso\scripts\Contact.ts
module Contoso {
export class Contact {
private static instance = new Contact();
//#region Form Properties
static fields = { }
//#endregion Form Properties
//#region onLoad / onSave
static onLoad(): void {
Contact.instance.onLoad();
}
private onLoad = (): void => { ...}
static onSave(): void { Contact.instance.onSave(); }
private onSave = (): void => { ... }
//#endregion onLoad / onSave
}
}
These files may have dependencies on other common files/classes:
// File Path .\_Abc\scripts\CommonLib.ts
module ABC_Corp {
export class CommonLib {
...
}
}
// File Path .\_Abc\scripts\RestLib.ts
module ABC_Corp {
export class RestLib {
...
}
}
// File Path .\_Abc\scripts\RoleLib.ts
module ABC_Corp {
export class RoleLib {
...
}
}
All these files currently reside in a VS Website Project. When I save the ts files, they are compiled into JS which I then deploy to CRM.
Now, with RequireJS in the mix, I have created a Contoso.Require file that reads the require configuration from the CRM OnLoad function call and triggers the appropriate onLoad method on the form script. While this setup successfully loads the main form JS and calls the onLoad function, I am facing an issue where I have to manually define the required JS files in the CRM OnLoad Event instead of having each file specify its dependencies. How can I designate the files needed by each class/file?