javascriptrequirejsrequirejs-text

Configure location of text.js


I'm using requirejs with the text plugin. By default, requirejs assumes text.js lives in your baseUrl. However, I want to keep it somewhere else. Where/how/when do I need to configure requirejs?


Solution

  • You can use requirejs's path config for this. From the documentation:

    paths: path mappings for module names not found directly under baseUrl. The path settings are assumed to be relative to baseUrl, unless the paths setting starts with a "/" or has a URL protocol in it ("like http:").

    So you could do something like this:

    requirejs.config({
      paths: {
        "text": "/absolute/path/to/text.js"
      }
    });
    

    Then you can use text as a dependency in modules and require.js will know to look for the file in /absolute/path/to/text.js.