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

Is there an equivalent for webpack.resolve.alias? #3526

Closed
dharnnie opened this issue Nov 30, 2017 · 2 comments
Closed

Is there an equivalent for webpack.resolve.alias? #3526

dharnnie opened this issue Nov 30, 2017 · 2 comments

Comments

@dharnnie
Copy link

dharnnie commented Nov 30, 2017

Hello, I was wondering if there is a way to resolve paths with an app created with CRA (create-react-app).

Like that.

resolve:{ alias:{ app: path.resolve(__dirname, 'src/app/'), } } in webpack

It's always a pain to to do this

import Header from '../../Header'
Or a way to configure if I ever eject.

If there isn't. Will be great to add that capability.
Thank you.

@tharakawj
Copy link
Contributor

CRA internally use webpack, so you can find the webpack configuration in config folder and you can change them as you want after ejecting.

Also, there is one way to use absolute paths without ejecting though you don't get much flexibility like webpack aliases. CRA respect NODE_PATH environment variable. So you can set NODE_PATH=src and import anything in the src folder directly like import Header from "app/Header" assuming there is a src/app/Header.js file. To configure this environment variable you can either use .env file or use a tool like cross-env with npm scripts. This issue has been extensively discussed in #741.

@tgrrr
Copy link

tgrrr commented Oct 10, 2018

Solution is here:
#2188 (comment)

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

3 participants