My project uses the text plugin for requirejs, and although the plugin works properly, the optimizer does not. This a test of my application file:
define([
'jquery',
'underscore',
//'ui/js/form/LoginForm'
'text!core/ui/text/form/LoginForm.txt'
], function($, _, template) {
var initialize = function() {
}
return {
initialize : initialize
};
});
This is the configuration:
require.config({
paths : {
jquery : 'lib/jquery/jquery',
underscore : 'lib/underscore/underscore',
text : 'lib/require/text'
},
shim: {
underscore: {
exports: '_'
}
}
});
require([
'app',
], function(App) {
App.initialize();
});
And this is the build configuration:
({
baseUrl: '../scripts',
mainConfigFile: '../scripts/main.js',
name: '../scripts/main',
out: '../scripts/concatenated-modules.js',
optimize: 'none',
optimizeAllPluginResources: true
})
I know without a doubt that the paths in the project are correct as the application itself works. However when building I get this:
C:\wamp\www\build>java -classpath js.jar org.mozilla.javascript.too
ls.shell.Main r.js -o build.js
Tracing dependencies for: ../scripts/main
InternalError: The choice of Java constructor append matching JavaScript argumen
t types (null) is ambiguous; candidate constructors are:
class java.lang.AbstractStringBuilder append(java.lang.StringBuffer)
class java.lang.AbstractStringBuilder append(java.lang.String)
class java.lang.AbstractStringBuilder append(java.lang.Object)
class java.lang.AbstractStringBuilder append(java.lang.CharSequence)
class java.lang.AbstractStringBuilder append(char[]) (r.js#21883(eval)#307)
In module tree:
../scripts/main
app
text
InternalError: The choice of Java constructor append matching JavaScript argumen
t types (null) is ambiguous; candidate constructors are:
class java.lang.AbstractStringBuilder append(java.lang.StringBuffer)
class java.lang.AbstractStringBuilder append(java.lang.String)
class java.lang.AbstractStringBuilder append(java.lang.Object)
class java.lang.AbstractStringBuilder append(java.lang.CharSequence)
class java.lang.AbstractStringBuilder append(char[]) (r.js#21883(eval)#307)
In module tree:
../scripts/main
app
text
My guess is that the optimizer was unable to realize that the 'text!core/ui/text/form/LoginForm.txt' text dependency used a plugin.
What I wanted was inline resources, I’ve been following the tutorials to the letter and I have all the latest versions of all libraries.
It appears the Rhino tool has problems understanding the text! plugin when compiling with r.js
I switched to Node and everything works perfectly.
For others who may encounter the same problem, simply go to the nodejs website and download the windows installer (I am using windows). Once installed restart your computer, and you can use
node r.js -o app.build.jsas explained on the requirejs website.