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

Webpack.config.dev.js resolve.root = path.resolve('src')... the key to happiness #1607

Closed
OlivierCo opened this issue Feb 21, 2017 · 3 comments

Comments

@OlivierCo
Copy link

OlivierCo commented Feb 21, 2017

I propose to add this:

resolve: {
    root: path.resolve('src')
    ...
}

in webpack.config.dev.js

The benefit of this is the following one:

Let say I have the following file structure:

/src
  /actions
  /components
  /views
    /App
      index.js
      styles.css
  index.js
  index.css

let say I need to call views/App/index.js from src/index.js
With the current webpack.config.dev.js I have to do this:

import App from './views/App';

and this is just a simple use case, I let you imagine if you have to call a component 3 or 4 levels before you should have something like:

../../../components/myComponent

such a pain, such a shame

with

resolve: {
    root: path.resolve('src')
    ...
}

it becomes now so easy and beautiful...

import App from 'views/App';
import BlahBlah from 'components/BlahBlah'; // wherever this is from, it can be so deep in your this no matter
@gaearon
Copy link
Contributor

gaearon commented Feb 21, 2017

Thanks for the suggestion! Please search past issues for existing discussions about this.

#253
#388
#636
#651
#741
#1043
#1065
#1136
#1492

tl;dr:

  • We won't be adding anything that breaks Node resolution algorithm and tools that depend on it.
  • You can sorta emulate this behavior today by using NODE_PATH environment variable and running NODE_PATH=src npm start and other commands.
  • We are still discussing how to fix this in the best way for the future, but it won't be involving modifying Webpack config. We'll likely suggest using a monorepo setup with something like Lerna and symlinks, but details are being worked out.

Hope this helps!

@OlivierCo
Copy link
Author

Sorry I didn't search indeed. Thanks

@gaearon
Copy link
Contributor

gaearon commented Feb 21, 2017

No worries 😉

@lock lock bot locked and limited conversation to collaborators Jan 22, 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

2 participants