Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I custom modulesDirectories ? #1591

Closed
suhaotian opened this issue Feb 20, 2017 · 10 comments
Closed

Can I custom modulesDirectories ? #1591

suhaotian opened this issue Feb 20, 2017 · 10 comments

Comments

@suhaotian
Copy link

suhaotian commented Feb 20, 2017

├── src
│   ├── App.js
│   ├── assets
│   │   └── logo.png
│   ├── components
│   │   ├── Counter.js
│   │   ├── Hello.js
│   │   └── Todo.js
│   ├── main.js
│   └── router
│   └── index.js

I just want to write like this to import componets in App.js:
(It's good for deep nested folder to import components.)

import Todo from 'components/Todo'

not

import Todo from './components/Todo'

I don't want to run eject, thank you !

@suhaotian
Copy link
Author

#1136

@gaearon
Copy link
Contributor

gaearon commented Feb 21, 2017

See my reply in #1607 (comment).
Please search past issues before creating a new one.
Thank you!

@gaearon gaearon closed this as completed Feb 21, 2017
@JustinTRoss
Copy link

The two issues mentioned above cover resolve.root (absolute path) configuration rather than resolve.modulesDirectories (hierarchal modules folders).

Any suggestions on how to achieve this without ejecting or having node_modules folders all over the place?

@gaearon
Copy link
Contributor

gaearon commented May 21, 2017

If you want arbitrary folders to have the same behavior as node_modules, that's not supported. This is just not how Node resolution algorithm works, and we do our best to stay compatible with it. Please symlink any custom folders to node_modules if it is important to you.

@JustinTRoss
Copy link

10-4. Thanks.

@Altiano
Copy link

Altiano commented Jul 1, 2017

@gaearon How about add another environment variable like customResolveModules or something like that.
And in paths.js or webpack.[dev|prod].js the variable should be injected.

@gaearon
Copy link
Contributor

gaearon commented Jul 1, 2017

I don’t think we’ll do that. We don’t want to significantly deviate from Node resolution algorithm. Instead we’d want to push the ecosystem towards solutions that work well within it.

@Altiano
Copy link

Altiano commented Jul 1, 2017

Yeah there are many hacky ways for typing less when requiring local module, guess we need to stick with those. But I'm wondering what is your recommended solution to require component from deeply nested module?

*) Maybe the solution could be places in User Guide section, so there are no more similar issue

@gaearon
Copy link
Contributor

gaearon commented Jul 1, 2017

You can put NODE_PATH=src in your .env file.

@Altiano
Copy link

Altiano commented Jul 1, 2017

@gaearon cool!

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants