duojs / duo

A next-generation package manager for the front-end
3.42k stars 118 forks source link

Adding folders to require path #377

Open joshrtay opened 9 years ago

joshrtay commented 9 years ago

If all the local components for an app are in lib, then it would be nice to be able to require('lib/component'). In browserify this functionality is enabled by adding a symlink to the lib folder in the node_moduels folder. What is the equivalent in duo?

kvnneff commented 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.

beverlycodes commented 9 years ago

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')

joshrtay commented 9 years ago

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.

kvnneff commented 9 years ago

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.

joshrtay commented 9 years ago

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.

cristiandouce commented 9 years ago

I think this is what applies: https://github.com/duojs/main

And also this one for css: https://github.com/duojs/css-compat