Open joshrtay opened 9 years ago
Just using the path works for me:
require('/lib/component')
Some don't like the beginning /
but I haven't had any problems requiring local components this way.
This ties in with an ongoing discussion in PR #372. As of now, the only two ways to reference local components are via relative paths, or via an "absolute" path that is absolute from Duo.root (or where Duo was run from on the command line, or where the --root option points).
If lib is in the root, then you can require('/lib/component')
ok. cool.
and when you require('/lib/component')
it just includes /lib/component/index.js
? is there anyway of specifying that the entry for that folder should be lib/component/component.js
? local requires dont seem to be respecting component.json files.
As @ryanfields mentioned, #372 explains how Duo ignores paths
and locals
in a component.json.
But you can require any local file like var Component = require('/lib/component/entry.js')
. For remote components you can require('component/some-component:entry.js')
.
And to answer your first question, you're correct in that any require('/lib/component')
statement expects an index.js
to be located in /lib/component/
otherwise it won't be included in your build.
it seems like the default behaving for require('/lib/component')
should be to look for /lib/component/component.json
, then /lib/component/index.js
, then /lib/component.js
and then log unresolvable.
I think this is what applies: https://github.com/duojs/main
And also this one for css: https://github.com/duojs/css-compat
If all the local components for an app are in
lib
, then it would be nice to be able torequire('lib/component')
. In browserify this functionality is enabled by adding a symlink to thelib
folder in thenode_moduels
folder. What is the equivalent in duo?