Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to add pre-existing static HTML page to a React/Gatsby site

I have a simple project working nicely using JSX / React / Gatsby.

I have a pre-existing page (think landing page) in HTML in another project, quite complex, nicely styled using Bootstrap 4, let's call it LandingPage.html and an associated LandingPage.css.

I would like to add the landing page to my Gatsby site. So that for example when navigating to localhost:3000/LandingPage.html the landing page gets shown, properly styled etc.

I am not clear whether I have to fully convert my pre-existing HTML into a react component / JSX? Or whether I can just serve the LandingPage.html (and associated styling files) by placing it somewhere sensible in my Gatsby project structure? Or whether I have to create a react "wrapper" that at "run time" reads in the content of LandingPage.html and LandingPage.css?

Note: I've tried just putting the LandingPage.html and LandingPage.css into the /public folder and actually that does work! So maybe I've answered my own question. But is the the right way to do it?

like image 965
ubienewbie Avatar asked Jun 17 '18 09:06

ubienewbie


People also ask

Is Gatsby faster than React?

Gatsby is the best way to develop static webpages with React. Gatsby sites are incredibly fast to build, and they are equally quick in performance.

Is Gatsby a static site generator?

Gatsby, on the other hand, is a static progressive web app (PWA) generator that offers code and data splitting out of the box. To boost performance, Gatsby loads only critical HTML, CSS, JavaScript, and other data.

What is Gatsbyjs good for?

Gatsby enables developers to build fast, secure, and powerful websites using a React-based framework and innovative data layer that makes integrating different content, APIs, and services into one web experience incredibly simple.

Where is HTML js in Gatsby?

Gatsby uses html. js in the src folder. Not index. html like most react projects.


1 Answers

As of Gatsby v2 (don't know about previous versions), it is maybe more consistent to add the file to the /static folder.

According to the docs, the /public folder is meant to be generated automatically when building the site and should be added to .gitignore.

Files added to the /static folder will be copied to /public when building the site so it should have the same effect. More info here.

like image 129
Federico Rodríguez Avatar answered Oct 11 '22 18:10

Federico Rodríguez