I'm new to RequireJS. I'm writing a number of custom bindings in Knockout.js and want to split them up using modules.
The layout of my code at the moment is:
/
default.html
js
code.js
require-config.js
lib
/require.js
bridge
bridge.js
bindings1.js
bindings2.js
bindings3.js
I want to load bridge.js from default.html and have that load in all of the bindings files. I've tried loading bridge.js using a or inline js using the require function.
My require-config is very simple:
require.config({
baseUrl: '/'
});
In bridge.js, I am having problems loading the files using a relative path. I tried:
require(['./bindings1', './bindings2', './bindings3'], function () {
console.log('loaded');
});
But this just ends up using the path baseUrl + 'bindings1.js', for example. I've tried various iterations in bridge.js. The only success I've had is if I write the entire path:
require(['js/bridge/bindings1', 'js/bridge/bindings2', 'js/bridge/bindings3'], function () {
console.log('loaded');
});
But that is not what I want. This seems like a pretty basic use case and I think I may be misunderstanding how the relative paths work.
Thanks
baseUrl
that you set up. For example: if u set upbaseUrl: '/js/lib/bridge'
, then you can use:require(['bindings1', 'bindings2', 'bindings3']
– Cristi Pufu