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?
Asked
Active
Viewed 687 times
3

pje
- 21,801
- 10
- 54
- 70
2 Answers
3
To add to shioyama's answer, the .js
in the "/absolute/path/to/text.js"
is not necessary. It is appended when require.js checks the path:
requirejs.config({
paths: {
"text": "/absolute/path/to/text"
}
});

Andrew Myers
- 2,754
- 5
- 32
- 40

Asnogordo
- 56
- 5
2
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
.

Chris Salzberg
- 27,099
- 4
- 75
- 82
-
So plugins are configured using `paths` as well. Great—thanks! – pje Nov 07 '12 at 01:57
-
1Heh, I've never even worked with plugins, but basically AFAIK require.js treats all files equally. See e.g.: http://stackoverflow.com/questions/7363379/requirejs-order-plugin-can-it-exist-in-a-different-path-than-the-require-js-bas (a bit old but still true). – Chris Salzberg Nov 07 '12 at 02:05