16

Ok, I already know that you should configure paths with RequireJS like this

require.config({
  paths: {
    name: 'value'
  }
});

And call it like this.

require(['name'], function() {
    /* loaded */
});

But the thing is, I'm working in environment in which I don't have access to the existing call to require.config(...). For those who care, the environment is Azure Mobile Services scheduled job. Microsoft has already included RequireJS in the environment and configured the paths. My question is two-fold.

1. How do I add paths to the existing require.config()? I know calling require.config() again will destroy the existing configuration. Which is what I do not want to do.

2. How do I get to know which paths have already been configured? I really wouldn't like to overwrite any existing path name or overwrite any existing library by accident.

Jani Hyytiäinen
  • 5,293
  • 36
  • 45

1 Answers1

27

Running require.config() again does not override your original config file. It actually extends it and adds your new paths to it. Right now I am using it this way, where configfile is also a require.config({})

<script data-main="configfile" src="require.js"></script>
<script>
    require.config({
        paths: {
            prefix-name: 'path/to/file'
        }
    });
</script>

One way to avoid name collisions with Azure Mobile paths would be to simply prefix all your custom paths.

Disclaimer: I have never used Azure Mobile, just RequireJs. You may have to implement it a little differently but it is possible.

Matt Derrick
  • 5,674
  • 2
  • 36
  • 52