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

Don't share public folder between dev and build #4512

Closed
borekb opened this issue Mar 13, 2018 · 6 comments
Closed

Don't share public folder between dev and build #4512

borekb opened this issue Mar 13, 2018 · 6 comments

Comments

@borekb
Copy link
Contributor

borekb commented Mar 13, 2018

I've been working with Gatsby for the past few days and have already been bitten by the fact that the /public folder is shared between the dev server and the eventual build. Maybe as a workaround I could use something like gatsby build --output-dir dist as proposed in #1878 but I still think it's generally a bad idea to let dev server influence the build and vice versa (it happened to me).

@KyleAMathews
Copy link
Contributor

What problems specifically did this cause you?

@borekb
Copy link
Contributor Author

borekb commented Mar 13, 2018

It was around loading external <script>s (think jQuery) which is generally tricky in React and may behave differently between dev server and the generated site. In my specific case, the scripts were not loaded on the dev server, then I ran the build in a separate console window and suddenly, the dev started working.

Maybe riskier is the other way around: if I'm not aware of this shared folder dependency, I would expect that when I run gatsby build and then deploy the public folder, it would surely be my built site. This is not guaranteed if I forgot that a dev server is running in another console.

You could say that my workflow was problematic or that I didn't understand enough of how <script> works in React, and you'd be right. Still, I think that production build simply should not be influenced by a dev server.

@KyleAMathews
Copy link
Contributor

Hmmm I'm still not sure what happened.

Generally though, the workflow we support is importing the jquery (or other packages) from NPM and letting webpack bundle your JavaScript together. You should rarely if ever be writing <script> tags.

So:

npm install --save jquery

# In a react component where you use jquery
import jquery from "jquery"

If you can figure out how the dev server and production builds interacted — it'd be great to fix that.

@borekb
Copy link
Contributor Author

borekb commented Mar 14, 2018

Thanks. Maybe a question: when I do gatsby develop and there was previously something generated in public by gatsby build, will anything be overwritten? Wait, I won't be lazy and try..

@borekb
Copy link
Contributor Author

borekb commented Mar 14, 2018

Yeah, the differences are vast. So the problematic scenario from above can easily happen.

image

@KyleAMathews
Copy link
Contributor

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants