0

I have a durandal project and I'd like to try and improve the way I work with modules in my project.

I have a configuration below:

requirejs.config({
    paths: {
        'text': '../Scripts/text',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions',
        'shared': 'shared'
    }
});

I have added the utils entry. The utils folder has the following structure:

main.js
+App
     +shared
         -utils.js
         -globals.js
         ...

So I was hoping in my define callback to be able to address the utils module as follows:

define(['shared/utils'], function(utils) {
    //do stuff
});

Essentially I'd like this to work inline with the durandal callbacks.

I note a call to:

 utils.js and not shared/utils.js in the web inspector.

Thanks

Captain John
  • 1,859
  • 2
  • 16
  • 30
  • Just drop the path Entry. Your define in the submodule is relative to APP folder thus should already work. – zewa666 Apr 09 '14 at 06:10

2 Answers2

0

The require js docs state that paths are relative to the baseUrl.

e.g

requirejs.config({
baseUrl : "/App",
paths: {
    'text': '../Scripts/text',
    'durandal': '../Scripts/durandal',
    'plugins': '../Scripts/durandal/plugins',
    'transitions': '../Scripts/durandal/transitions'
}});

Therefore assuming your baseUrl is the same as the durandal default '/App', your config should look like this:

requirejs.config({
baseUrl : "/App",
paths: {
    'text': '../Scripts/text',
    'durandal': '../Scripts/durandal',
    'plugins': '../Scripts/durandal/plugins',
    'transitions': '../Scripts/durandal/transitions',
    'shared': '../shared/'
}});
  • Thanks. Was aware it's a a relative path. Have added a little further clarification on where the utils.js file is located. – Captain John Apr 08 '14 at 17:06
0

I think that your main.js file needs to be within the App folder for those URLs to match up correctly.

Alexander Preston
  • 1,665
  • 11
  • 15