-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Document existing work-around for absolute imports. #693
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,34 @@ class Button extends Component { | |
export default Button; // Don’t forget to use export default! | ||
``` | ||
|
||
To import your own modules into other files, you can use relative paths by default. For example: | ||
```js | ||
import Banana from '../../Banana'; | ||
``` | ||
You can also enable absolute paths by adding a NODE_PATH environment variable. This is a bit of a stop-gap measure for now. Here is an example absolute import and the commands you would need to run for it to work: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let’s put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let’s expand “This is a bit of a stop-gap measure for now.” into “We don’t recommend this at the moment, and we encourage you to use relative paths for your projects if you can. However, this can be used as a stop-gap measure if you’re porting a large project to Create React App. In the future, we intend to offer a better way of handling absolute imports.” |
||
|
||
```js | ||
import Banana from 'fruits/Banana'; // fruits is a subdirectory of src | ||
``` | ||
|
||
If you use Bash on OS X or Linux: | ||
|
||
```js | ||
NODE_PATH=./src npm start | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe let’s recommend doing this inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do that, we might as well tell people to |
||
NODE_PATH=./src npm run build | ||
NODE_PATH=./src npm test | ||
``` | ||
|
||
If you use Cmd on Windows: | ||
|
||
```js | ||
NODE_PATH=./src&&npm start | ||
NODE_PATH=./src&&npm run build | ||
NODE_PATH=./src&&npm test | ||
``` | ||
|
||
Note that lack of whitespace on Windows is intentional. | ||
|
||
### `DangerButton.js` | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would work better as a separate section called “Absolute Imports”. I would put it right before “Can I Use Decorators?” so that it’s there, but doesn’t distract from the usual way of doing things.