Search code examples
javascriptrequirejsdurandallinq.jsweyland

Using Linq.js with Durandal/Require.js


I have done the following setup:

  1. Added the following script tag:

    <script src="Scripts/linq.js"></script>
    
  2. Configure linq.js in the main.js

    requirejs.config({
    paths: {
        'text': '../Scripts/text',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions',
        'knockout': '../Scripts/knockout-2.3.0',
        'jquery': '../Scripts/jquery-1.9.1,',        
        'linq': '../Scripts/linq'
    }
    // The ko in this project is already AMD
    , shim: {        
        linq : {
            exports: 'Enumerable'
        }
    }   
     });
    
  3. Attempt to get a copy of it in one of my viewmodel (shell.js) like this:

    define(['plugins/router', 'durandal/app','linq'], function (router, app, linq) 
    
  4. Optimizing the build using weyland, however I'm getting:

Error 1 ENOENT, no such file or directory 'C:\Project\build\App\linq.js' C:\Project\

I'm new to this, did I get anything wrong?

I thought the shim should point to the global variable, which I did.

Do I need to create my own define in addition to the shim? I thought Shim is supposed to be a syntactic sugar wrapper over define over a global variable?


Solution

  • A shim shouldn't be required in this situation, where linq is include via script tag. Just make sure load linq via script tag before loading main.js via require.js. Next remove the configuration entries and the dependency.

    requirejs.config({
        paths: {
            'text': '../Scripts/text',
            'durandal': '../Scripts/durandal',
            'plugins': '../Scripts/durandal/plugins',
            'transitions': '../Scripts/durandal/transitions',
            'knockout': '../Scripts/knockout-2.3.0',
            'jquery': '../Scripts/jquery-1.9.1,'
            }
        }   
    });
    
    
    define(['plugins/router', 'durandal/app'], function (router, app){...
    

    That way there's no need to configure weyland to exclude it.