Using absolute instead of relative paths
See original GitHub issueI would like to use absolute paths instead of relative paths in Gatsby if it’s possible.
For example, in the tutorial for using component css
import React from "react";
import Container from "../components/container";
export default () => (
<Container>
<h1>About CSS Modules</h1>
<p>CSS Modules are cool</p>
</Container>
);
instead of using ../components...
I would like to use src/components/...
I’ve done some google’ing, but haven’t been able to figure it out. I’ve used .env file in the past with create-react-app. Is there a way to edit the .babelrc
file in Gatsby or some other way to accomplish this?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Absolute vs Relative Path - Which Should You Be Using?
"Using absolute links for images allows you to assert ownership in the image search results, which reduces the likelihood of duplicate content ...
Read more >Absolute and Relative Pathnames in UNIX - GeeksforGeeks
A path is a unique location to a file or a folder in a file system of an OS.A path to a file...
Read more >Difference between Relative path and absolute path in javascript
The difference between relative and absolute paths is that when using relative paths you take as reference the current working directory ...
Read more >What is the difference between a relative and absolute path?
In the example above, the absolute path contains the full path to the cgi-bin directory on that computer. The relative path begins with...
Read more >What are the differences between absolute and relative paths?
Absolute paths are useful, but they're not always efficient. If you know where the widgets directory, which contains button , is located. then ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Check out gatsby-plugin-resolve-src by @alampros. Would that work? Wouldn’t be
src/components/...
but rathercomponents/...
, which I find preferable.I’d love something similar for Sass. I haven’t spent too much time digging for something better, but right now I do the following in
gatsby-node.js
:…which allows for imports like this in Sass:
…as opposed to what’s required currently:
@alampros Thanks for the awesome work on
gatsby-plugin-resolve-src
.I tried your proposed solution, but couldn’t get it to work, at least in my project. FWIW, relative imports don’t need that variable usage.