Loading multimodule package does not work
feklee opened this issue · 2 comments
I installed my own package ptp.js. From bower.json
:
"dependencies": {
"ptp.js": "2.x",
"requirejs": "2.x"
},
From Gruntfile.js
:
bower: {
target: {
rjsConfig: 'package/config.js'
}
},
Resulting config.js
:
require.config({
shim: {
},
paths: {
ptp: "bower_components/ptp.js/scripts/ptp",
requirejs: "bower_components/requirejs/require"
},
packages: [
]
});
Now, to load ptp.js
, the app's main module has:
defined(['ptp'], function (ptp) {
// …
}
ptp.js
loads fine, but not any modules that it depends on. To fix this, I modify config.js
to match what @jrburke does in his template for a simple one-page app:
paths: {
ptp: "bower_components/ptp.js/scripts",
Then to load the module, I use:
defined(['ptp/ptp'], function (ptp) {
// …
}
Now, the dependencies load. The trick is to set the path to the directory containing the main module of the package to be loaded. If loaded as ptp/ptp
, then relative paths work fine, otherwise not.
I think there is design issue that needs to be discussed, or there is something that I don't understand.
What do you think?
Looking at your ptp component, you need to fix the main
reference in your bower.json
file (https://github.com/feklee/ptp.js/blob/master/bower.json#L8). It should be pointing to a file (or multiple), not a directory. So that could be causing some of your problems.
Try changing it to this:
"main": "scripts/ptp.js"
Pointing "main"
to "scripts/ptp.js"
causes the issue that relative paths are not found. Pointing it to a directory is the only workaround that I found.