I'm having an issue getting the text! plugin to work in my requirejs site. It's always including lib/ in the request url, however all of the other files (not using text!) are being successfully found and loaded. Here is my directory structure:
WebContent/
|--backbone/
|--Bunch of folders and files
|--config/
|--config.js
|--lib/
|--jquery.js
|--text.js
|--require.js
|--index.html
my index.html file is:
<body>
<div id="siteLayoutContainer"></div>
<script data-main='config/config' src="lib/require.js"></script>
</body>
The config file is:
requirejs.config({
baseUrl: './',
paths: {
jquery: 'lib/jquery.js',
backbone: 'lib/backbone.js',
text: 'lib/text',
application: 'backbone/application'
},
text: {
env: 'xhr'
}
});
require(['application'], function(App) {
App.start();
});
I'm using the text! plugin like so:
define([
'jquery',
'text!backbone/templates/SomeTemplate.html'
], function(jQuery, NotFoundHtml) {
//Some code here
}
So, in the above script, the url being used for the template is: http://localhost/lib/backbone/templates/SomeTemplate.html
and I am expecting it to be: http://localhost/backbone/templates/SomeTemplate.html
I've tried the following:
- Moving the text.js and require.js files out into the WebContent directory but I get the same results. Also something interesting is if I put a space after text! and then the path, that works fine and doesn't include the lib/ directory in the request to get the html template. However the optimizer includes the space and can't find the template.
- Not defining a baseUrl - same results.
- Moved the require config.js content into index.html in it's own script tag that runs before the require.js script tag - same results.
- Getting rid of the the text options in the config file
- Oh yeah, forgot I've also tried 'text!../backbone/templates/SomeTemplate.html - same results
So I'm stuck and can't figure out what I'm missing. I'm obviously not understanding how the text! plugin uses the baseUrl or how it determines the url it's going to use to fetch the defined file.