I\'m struggling with all the Script# Dependency loading.
I have a Script# Project referencing the knockout library. Which I got to work after some time with RequireJ
It sounds like Script# is assuming that ko
and ko.mapping
are in the global namespace, not loaded as AMD. BUT, Knockout and Knockout.mapping are coded such that when they detect AMD/RequireJS, they do not use the global namespace.
A couple options to work around this:
1 - Inject it right after require.config is called (based on comments below) rather than waiting for something to actually request knockout or knockout.mapping
requirejs.config({
// same as original
});
require(["knockout", "knockout.mapping"], function (ko, m) {
ko.mapping = m;
})
2 - create your own wrapper module to inject it back into global. Something like this:
define('knockout.inject', ['knockout'], function(k)
{
window.ko = k; // make a ko global
return k; // but also return what a normal AMD require expects
});
define('knockout.mapping.inject', ['knockout.mapping'], function(m)
{
window.ko.mapping = m; // make a ko.mapping global
return m; // but also return what a normal AMD require expects
});
THEN, you can make a RequireJS map configuration so that whenever you request 'knockout' or 'knockout.mapping', they get transparently remapped to your above wrappers.
requirejs.config({
paths: { // same as original },
shim: { // same as original },
map: {
'*': {
'knockout': 'knockout.inject',
'knockout.mapping': 'knockout.mapping.inject'
},
// prevent cycles
'knockout.inject': {'knockout': 'knockout'},
'knockout.mapping.inject': {'knockout.mapping': 'knockout.mapping'}
}
});
This sample (https://github.com/nikhilk/scriptsharp/tree/cc/samples/KOWorld) shows using script# + knockout along with requirejs as the AMD loader.
Be sure to see the script template in AssemblyInfo.js to make all this work.
Hopefully this will help and work.