When shadowing a Gatsby theme how does one deal with import calls to components that does not need any changes. From my understanding the only files that should be present in the directory if you are shadowing are the source code for the component you wish to change.
For example in original index.js, I have the following imports
import { graphql } from "gatsby"
import React from "react"
import CustomFonts from "../components/custom-fonts/custom-fonts"
import Footer from "../components/footer/footer"
import Header from "../components/header/header"
import SEO from "../components/seo/seo"
import Sidebar from "../components/sidebar/sidebar"
import "../styles/style.css"
If i wanted to shadow index.js how would i import these components? or would all the imports have to be present locally?
I think this is the relevant Gatsby documentation on this? https://www.gatsbyjs.org/docs/themes/shadowing/#extending-shadowed-files ,but im still some what confused after reading it.
Any help would be much appreciated
3
Answers
Well this turned out to be a really dumb question, just use the plugin resolve path under gatsby-config.js
@CrustyWang ‘s answer is correct…but here’s how to do it in code.
Let’s say you have a module
fontcula
in yournode_modules
which has the following style files on the path –node_modules/fontcula/src/styles/
where index.ts is –
Let’s say we want to add a new set of fonts in a file
fonts.ts
which we want to be exported from index.ts. To do this we need to do the following –On the path
project_folder/src/fontula/styles
add font.ts and add whatever it is that needs adding there….on the same path recreate index.ts as –
and you are good to go.
The operative part being pulling in
globalStyles
andmedia
from their source in thenode_modules
folderIt wasn’t immediately clear to me either. You need to use the node module location for your import, in a shadowed file, instead of a relative path. In my case:
Instead of