Next.js Discord

Discord Forum

Can I use Nextjs to export just the front end part of React?

Answered
Whiteleg shrimp posted this in #help-forum
Open in Discord
Whiteleg shrimpOP
Hi guys, I am new to Nextjs

I wonder can Nextjs be used to generate React frontend code only like I used to generate with CRA.
I ask because CRA is not supported anymore and I am php developer i mean backend developer but I also write js (as fullstack) and I need something to replace CRA on frontend.
Is it possible from Nextjs to export only the part of front end React without Nextjs backend in order to use with a php backend?
Answered by Kokoni
No. The only option to eject is to give you static HTML or transpiled Javascript.
View full answer

42 Replies

@Rafael Almeida yeah you can use the static export option: <https://nextjs.org/docs/app/building-your-application/deploying/static-exports>
Whiteleg shrimpOP
So I could use Nextjs as a generator for the boilerplate for a frontend React project?
Or It is even more, so I can export an entire finished project made in Nextjs to a frontend React project only.
it exports the project as static files so you can host them like a SPA, without a dedicated Node server
you can use any backend with it
@Rafael Almeida it exports the project as static files so you can host them like a SPA, without a dedicated Node server
Whiteleg shrimpOP
So I can do that after the project is finished, not only at the beginning like for CRA to create a starting boilerplate?
I am not sure I understand the question, this is only one of the many ways to build the project with Next. you can build the project (running next build) whenever you want
Kokoni
@Rafael Almeida they specifically want to be able to edit it as React again
not NextJS or HTML or JS
but actual React
is that right @Whiteleg shrimp ?
@Kokoni not NextJS or HTML or JS
Whiteleg shrimpOP
Yes
I mean to use as a boilerplate code generator, like create react app CRA
Kokoni
Hmm I do not think there is a native way of doing this :( I am sorry!
@Whiteleg shrimp I mean to use as a boilerplate code generator, like create react app CRA
Himalayan
Vite is properly the closest you get to something that worked like CRA its also what laravel uses im pretty sure
Kokoni
That still doesn't solve the problem of ejecting the Next part of the app.
Whiteleg shrimpOP
Static export is just exporting HTML for Seo purpose?
Kokoni
Yep! or even deployment purposes
Sometimes you just want to deploy static HTML/JS/CSS
@Kokoni Yep! or even deployment purposes
Whiteleg shrimpOP
Deployment purpose can be export as SPA not as SEO friendly
Kokoni
I understand :) Next just doesn't have this right now. Exporting as an SPA simply exports to Javascript that acts as an SPA I believe
@Kokoni I understand :) Next just doesn't have this right now. Exporting as an SPA simply exports to Javascript that acts as an SPA I believe
Whiteleg shrimpOP
So there are 2 types of export in Nextjs as SPAand as static HTML?
Kokoni
Well, a static export is either static or an SPA, and the SPA is just going to give you transpiled Javascript, not React
@Kokoni That still doesn't solve the problem of ejecting the Next part of the app.
Whiteleg shrimpOP
Is there any feature of ejecting like it was in CRA, to get rid of extra backend code?
Kokoni
No. The only option to eject is to give you static HTML or transpiled Javascript.
Answer
Kokoni
There is no option to eject as React.
Whiteleg shrimpOP
How one can choose between static HTML and transpiled js?
What commands are for that?
Kokoni
You don't I don't think. I think Next automatically chooses.
@Kokoni You don't I don't think. I think Next automatically chooses.
Whiteleg shrimpOP
How does it knows which kind of export the user wants (static HTML or SPA) ?
Kokoni
If you have no client side functionality in your application it will export as static HTML
If you have any client side functionality it will export as an SPA
It will probably honestly always just export as an SPA
Whiteleg shrimpOP
Thank you for helping me
I will dig more into Nextjs to get familiar about how it works
Kokoni
Of course! Please mark one of my answers as an answer @Whiteleg shrimp :)
@Kokoni Of course! Please mark one of my answers as an answer <@411329675944656898> :)
Whiteleg shrimpOP
How I can mark? I looked for but discord doesn’t show such feature
Kokoni
@Kokoni Click to see attachment
Whiteleg shrimpOP
I tried al the menus but there nothing to mark the best answer on the iPad app
Kokoni
No prob!
Whiteleg shrimpOP
I marked the best answer with something like a smiley face by mistake and there is no way to remove it