Skip to content

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

Closed
@OlivierCo

Description

@OlivierCo

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

Activity

gaearon

gaearon commented on Feb 21, 2017

@gaearon
Contributor

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

OlivierCo commented on Feb 21, 2017

@OlivierCo
Author

Sorry I didn't search indeed. Thanks

gaearon

gaearon commented on Feb 21, 2017

@gaearon
Contributor

No worries 😉

locked and limited conversation to collaborators on Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @gaearon@OlivierCo

        Issue actions

          Webpack.config.dev.js resolve.root = path.resolve('src')... the key to happiness · Issue #1607 · facebook/create-react-app