Syntax Video
How To Create A React App in 2025
- 0:00 intro
- 0:45 drop-in replacement for create-react-app
- 2:29 tour of Vite + React app
- 5:03 how to migrate is later in the video
- 5:26 types of React apps
- 5:48 SSG with Astro
- 6:17 content driven website examples
- 9:55 astro simple app
- 10:25 tour of astro app
- 11:18 astro demo
- 15:16 SPA - heavy client rendered apps
- 17:11 SPA routing libraries
- 18:39 SPA data loading
- 20:09 SSR - dynamic, on-demand generated apps
- 23:55 hybrid apps
- 25:36 migrating from CRA
- 27:43 excalidraw vite migration example
- 30:52 full vite migration example
- 39:14 conclusions / takeaways
- 40:08 thanks
intro
create react app has been officially deprecated and in this video we're going to talk about what to use instead now you could call this CJ's opinionated guide to creating a react app because if you look at their announcement blog post and if you look in the actual react docs they go through a lot they they just talk about so much in order for you to just be able to create a react app and most people just want to get building and so in this video I'm going to talk about how you can create react apps I'll talk about all the ways that they mention but I'll kind of group them into categories and really give you some questions you can answer to then point you to how you should create your react app so that sounds good to you let's dive in my name is CJ welcome to [Music] syntax now first up is guidance for someone that was about to reach for create react app and somehow you found this video so welcome now if you were literally about to run create-react-app from the command line you have a simple answer as to what you should do instead
drop-in replacement for create-react-app
just use V right because create react app was essentially a wrapper around webpack it made it so that you didn't have to Define all of this webpack configuration you could just use some sensible defaults and vit gives you that exact same experience so if you check out v.d you can learn all about it you could dive into all of the documentation but it's a single command to spin up an application so literally all you have to do is in PM create V at latest and then choose react you could specify react from the command line but let's run it and I'll show you what we get so here I'm going to call this my vit react app and then you can choose your framework so this is the nice thing about vit is is used all over the front end ecosystem you can use it to create react apps spelt apps View apps angular apps and a lot of these meta Frameworks that we'll show examples of later on actually use vit under the hood so hands down vit is the answer here there there it's it's kind of crazy that people beat around the bush to say that V isn't the answer but it is just choose vit and here you
see we can choose react they also give you several options for whether or not you want to use typescript or JavaScript um I would say if you're going to go with react and typescript just choose the standard typescript op option and they also give you an option to spin up a v app that uses react router I'll show you an example of this in a second but we're going to choose typescript head into that directory install dependencies and then run it and when you look at that I have myself a react app so hands down the simplest replacement for create react app is V if you dive into the app we just generated there's a V.C config and you can see here that it uses the react plugin and so this is the nice thing about V is it's plug-in based and you'll see for all of these other ways of creating apps with v they just have their own plug-in defined so that they can define a bunch of other sensible defaults for you so you don't have to do all of that uh but this is nice because you can actually expand your Babel config you can add rollup plugins you can customize your build right from this one setting here without needing to
tour of Vite + React app
create highly custom configs aside from that everything else is fairly straightforward if you're coming from create react app so we have our index.html this is our entry point and one of the things that V uses when we're in development is known as es build and so you'll see something pretty interesting here we're actually pointing directly to a TSX file inside of this index.html but because V is using ES build when we're running in development when the development server receives a request for this file it actually transpiles it in real time and so that's one of the things that makes vit super fast is as you're working on your app it really only needs to compile and transpile the things as they're being requested instead of kind of doing it all in one go like you would often get with webpack now in the source directory also very simple you have your main entry point here that mounts your react app you have your react component here and then you have some CSS and so this is the other nice thing about beat is it's set up to support lots of different module types right you can see here that we're importing a CSS file what this
means in the context of V is it's actually going to create a style tag that has those Styles inside of them and that's just ready to go by default you can also see that this example Imports SBG files and so behind the scenes there's just a setup and ready to go SVG file loader that actually gives us back an asset URL that will be used whenever we build this application for production so if you're coming from create react app everything is kind of just ready to go you can just start working on your react components right inside of here and it has a hot refresh so if I change all of this to just say hello world and then head back back to the browser look at that it automatically refreshes so same Dev experience you're used to and you can just get start coding with feet um I would also recommend if you are a beginner or someone that's just learning the basics of react and how to build out components and how to use UST State and different things like that vit is a very easy on-ramp for that as well some of these other Frameworks we're going to look at introduce so many other things that as a beginner you could get very
confused as to what actually is react versus what is the framework and so I highly recommend if you were going to be using Create react app anyways just use V instead now another question you might have is what if you are migrating from create react app like let's say you spun up an app with create react app a month ago before you knew that it was getting deprecated and now you want to use a more supported tool I'm going to move this to later in the video because it gets a little bit involved because I show you some examples of more complex migrations before that we're going to jump into just the other various ways of creating a react app besides beat now when you set out to build an app with react you're probably setting out to build a specific type of application and the type of application you're going to build will determine what you could choose to use to build it and it sort of comes down to these various rendering strategies we're also going to talk about the type of websites that fall into these buckets but the first here we're going to talk about is SSG or static site generation and if your site is going to be statically generated my pick would be Astro now we'll talk about
how to migrate is later in the video
types of React apps
SSG with Astro
you can use some of these other tools to build SSG websites but Astro is hands down the best tool for this if that's the main thing that you're going to be doing so Astro is the web framework for Content driven websites so I think marketing landing pages blogs e-commerce sites things that are very content driven they have the Astro showcase that shows various websites that were built with Astro and I pulled a few of them out here to give you an idea of what we mean by content-driven websites the first is a Blog now blogs technically have somewhat Dynamic data right anytime there's a new blog post it needs to here on the website but if you only write a blog post every week or so or maybe every other day you could have a flow where all of that blog data actually lives in your codebase and then whenever you want to deploy your blog you just build the codebase and then push it out as static files and so Firebase actually built their blog with Astro and one of the things you'll notice about statically generated sites is they are
content driven website examples
insanely fast and that's because there's very little if any JavaScript on a site like this every single one of these blog post pages is literally just an HTML file that has the post itself inside of it but if you use Astro you get a more modern authoring experience because you could construct your site using react components you could have like a post component or a sidebar component or a button component you can use all the things you know about modern react development but at the end of the day all of that's going to get turned into static HTML and CSS and as little or no JavaScript as possible so one example is a block um the Ikea blog is actually written with Astro as well one one way you can tell is if you open up the source in command f for Astro you'll see some various Astro things that stuck around here but specifically their blog is built with Astro if you head into their e-commerce store I do believe this section is actually built with something completely different the thing that lets you look at products and add them to the cart but the landing page and all of
these blog posts are an astro app and so again this is It's just static content there isn't really any user interactivity here we're just showing the same stuff to every user user that visits the site it doesn't have to be dynamic at least this section of the IKEA site uh another example is the Utah geospatial Resource Center this is just a collection of HTML pages right got a bunch of pages that just talk about the various stuff that they do and uh they also have a Blog here but this was built with Astro another one I'll show you is react. so this is a course for learning react but react. itself the landing page was built with Astro and so this is just a single page that describes their course talks about how much it costs what it gives you Etc but you could imagine that you probably would want to have some actual react components if you're building out stuff that looks like this maybe there's like some svgs Etc this would be very cumbersome to do if you didn't have like modern tooling
so you can use something like Astro use modern tooling but then have like just a single landing page like this and then another thing that a lot of people use Astro for is documentation so the cloud flare developer documentation is actually built with Astro using a theme that they have that's called Starlight and so once you start to dive into their docks here let's for instance look at the DNS stuff all of this is built with Astro um and you might have come across documentation that has this similar layout this is the Starlight theme that you'd be looking for um and then one last site I'll show you is developer road maps so they have road maps for all kinds of developers like front end backend Etc but the way you can think about these kinds of sites is for the most part we're showing the same content to every user that visits our site it's not dependent on every user and the data isn't changing that often so yeah they have these road maps for all these various types technically they do allow you to log in and track your progress but it's not going to change the content that they're actually displaying so if you're building a site that's like any one of these that I displayed or if you
check out their showcase and maybe come across a site that's similar to one that you want to build Astro is the answer so let me show you how we can spin up an astro app we'll copy this command here let's run it with pnpm and make an astro app they have a really cool CLI as well all right so we're just going to call this Astro example and they do have like a Blog template they have that Starlight template we're just going to go with a minimal starter what I really want to show you is how we can create react components and then the resulting build is just HTML we'll install dependencies use git yeah coolest CLI I've used all day okay now let's let's head into that directory and check out codes now one thing to note is Astro is actually built on top of V but they have a lot of other niceties that they've just added in in sensible defaults but under the hood they are using vit as well if you take a look at the source directory their default layout here is to have a folder for all your pages and now this uses like file based routing so every file you have in here would be its own page by default in Astro they will they'll detect pages that are asro
astro simple app
tour of astro app
markdown MDX HTML or you can also Define uh endpoints and then you can also Define layouts which essentially wrap the rest of your component and uh use slot to Define how it's going to be rendered out there so you can see we have all of these Astro files that's just their way of defining components but you can see that it uses jsx so it's very familiar to a react developer but you actually can Define react components directly so in the Astro docs they have a command you can run which basically adds react support and then we can start creating react components and adding them to our Pages now to show you what I mean by content websites I went ahead and set up a demo here where I have a few different react components so I have this navbar component which has a few links in it I have this page links component which has the links but it displays them in a list and then I have this component that just takes in a message that's a string and then renders it out in an H1 so the common theme between all of these components is that they don't have any use State inside of they don't have any JavaScript we're
astro demo
literally just using jsx to render out some some content here and then for the app itself I have multiple pages so in Astro your pages have a Astro file extension and you can see we have this layout component which sets up the scaffolding of the HTML page and then also we have that navbar component which we're rendering onto every single page and then the page itself gets rendered into the slot and then on the pom page here we just are rendering out the links and we have this counter which we'll talk about in a second page one literally just pulls in page with message and sets says this is page one and it is wrapped in that layout page two exactly the same but it says page two page three exactly the same but it says page three but let's take a look at the actual website so if we run npm run Dev we get our site we have our homepage we can go to page one page two page three Etc and then if I do a pnpm run build you're going to see that it actually just generates HTML files now we do have this one Javascript file because we did enable the react integration but none of these generated
HTML files actually reference it but let me show you what I mean by this so we we wrote out our code like this right we have all these components we have this more Modern Way of of writing things out but if we look in the disc directory we can see that Astro just generates HT files so I'm just going to format this with prettier look at this our landing page is just a static HTML file so when somebody goes to visit this it doesn't bring in any JavaScript at all to be able to render out that nav and then if we take a look like at page one format this it's literally just an HTML file and you'll notice for all of these files they're not bringing in that client bundle because we're we don't have any client components yet we'll talk about that next um but that's really one of the main benefits of something like Astro is you can have this modern Dev experience but then the resulting output is just static files so you can host this on a static file server and it's going to be super fast because there's no JavaScript it doesn't have to load anything dynamically everything is completely statically built into the generated files here but we added this react integration what if we actually do want some client side interactivity well
for that they have this concept called islands and the idea being that the majority of your site can be statically built but there can be small sections that maybe require some interactivity that can load in JavaScript for that one section and so for our example we have this counter component and this has some state right it starts off as zero and then we click the button it increments that counter and it has to use JavaScript for this you'll notice that by default Astro doesn't load any JavaScript for it at all this button does not work and in order to make it work we have to tell it that this is an island so here whenever we load the component we can say client load and now it's actually going to load in the JavaScript for that one specific component and so now if we refresh now that counter actually does work and then whenever I build the application it's now going to actually like bundle that counter it's going to include the react runtime and everything else but the only page that needs that JavaScript is the homepage so if we take a look at index.html in the built app you can see
here that it's got itself a nice little Astro Island and it knows to pull in all of our scripts but if we look at one of the other pages that doesn't have any JavaScript on it it's just as simple as before right so when someone navigates to this page there's no need to load the react library or anything else so this is one of the benefits of static site generation and using a tool like Astro and hands down Astro is the tool to build sites like this and so if you're trying to build a site like this or any of the ones that I showed from the Showcase Astro is the way to go now next up are single page applications and this is a really good fit for things like internal tools anything with a lot of heavy client side interactivity so think applications running in inside the web browser like Gmail or a stock dashboard that shows you charts and real-time data essentially think of experiences where a user goes to the page and then kind of just stays on that one page they might click around and navigate to what
SPA - heavy client rendered apps
appears to be different pages but they're really just staying in that one experience and there's tons and tons of interactivity within that one experience and another type of app that fits into that category but might be slightly separate is if you're building a front end with react that needs to integrate with an external API so maybe you're working with a a separate backend development team and your API is built with Ruby or python or go or something like that and they want you to build a react front end for it typically a single page application is going to be the way to go now personally this is where I have spent 80% of my career in terms of the react apps that I build I typically am building internal tools I'm interactive dashboards things with heavy client experiences I'm not building things that necessarily need to be statically generated or or need to have search engine optimization because they're typically behind a firewall or they're typically highly Dynamic uh and so that's that's where my experience is coming from and the kind of apps that I typically build which is why I lean towards using something like V because
if you were using Create react app before it was a single page application you typically combine it with a routing Library like react router but that is a single page application and like I said the majority of my experience is building applications like this and we talked about vit already but vit is the answer if you're trying to build a single page application hands down and like I showed you can just run the CLI tool and then choose the react and typescript preset um but typically when you're building a single page application you also need some sort of client side routing solution now for routing there are two main players in the space react router and tan stack router if I had to build a single page application today I would choose react router just because I'm more familiar with it but I've been dabbling with tanack router it's really nice it has file based routing and really good typescript support um and they have a growing community so they're definitely a major player as well but personally I just have a lot of experience with react router now when you look at the react router docs you can actually see that there are two different ways to use react router they have framework mode
SPA routing libraries
and in framework mode they can do things like serers side rendering and they have a CLI tool that kind of generates everything for you that's preconfigured with vit because it still uses vit under the hood but has a lot more opinions about where you place things and and how to set stuff up if you have experience with create rea react app and react router you can follow the library documentation which basically just adds react router as a dependency and you can see here in the react router docs they tell you hey generate a v app choose react install react router and then just use it so it's nothing crazy to get react router set up basically you you add that provider there and then you can start to declaratively Define your routes inside of your app and like I said I'm most experienced with this so if I had to build a single page application today I would do it like this but there is the option of using the framework so plain and simple if I had to build a single page application with react today I would use V and then I would install react router as a dependency set up my routes in that way and I'd be Off to the Races now another thing you have to consider when building a single page application is your data
SPA data loading
loading strategy and you could just do it raw and by that I mean like use effect and use state for your loading variables and fetch that's a possibility but one of the nice things about react router is they actually have this idea of client data loaders just built in so for any given route you can Define that Hey whenever someone hits this route this is the data that needs to be loaded in and then you can write your components that can basically assume that when this component loads it has access to that data and so this idea of framework managed data loading was definitely popularized by tan stack query and so if I were building a single page application today I probably would combine react router with tan stack query now at this point we're kind of like building out our own stack but again it's it's the tools that I'm used to and the the tools that I know work for what I want to do but technically you could actually just use the data loading feature of react router especially if you're already using react router um it's interesting to see that both of these libraries have kind of
like converged to that point of both routing and also like data management because tanack has tan stack router and they also have tan stack query I'll also mention that if you want to easily get up and going with tanack router they actually have a CLI tool so this was released like roughly a week ago it's pretty new uh but it's good to go essentially it scaffolds out the app for you and uses vit under the hood but sets up tan stack router with all the sensible defaults and you can just run it from the command line like you do with any of these other CLI tools now our next category here is SSR or serers side rendering and this is any application where you want to generate the content that user will see on demand and have potentially custom experiences for different users depending on where they are in the world or if they're logged in or not or what their current state is and essentially generate custom content on the server side that then gets sent down to the browser for the user to see this is serers side rendering and these days there's just been more and more of a push to SSR for
SSR - dynamic, on-demand generated apps
applications and it makes sense for certain apps right if applications have highly Dynamic content and they need to be optimized for search engines SSR does make sense however modern search engines can still index single page applications that load data dynamically and art server rendered technically they might be ranked lower because maybe they're a little bit slower to load because that data isn't immediately available when the page is rendered I digress um SSR is a thing that for certain applications you might need but like I said 80% of my career I've been in this Zone where I'm building internal dashboards I'm building things that don't need that heavy server rendering component I'm building things that are integrated with existing apis or building apis that can be used by multiple clients not just web clients and so uh one of the ideas of of SSR here is is you are writing code that runs on the server that can talk to databases and do servery things but can also then put that data into react components that are then sent over the
wire and actually rendered in the user's browser with potentially less JavaScript needed now if I had to build an application like this today I wouldn't use react I'd use spel kit because I've spent a ton of time there but I will say and this is where I will lean on the the community and that nextjs is kind of the Top Choice when it comes to serers side rendering but they are not the only ones that can do this because like I showed react router actually has a framework piece and they allow you to do serers side rendering as well now react router formerly known as remix um now is uh just under the name of react router but uh this is also a very valid choice these days you you could potentially look at the the remix stocks but they're all remix and react router are now basically the same thing um and I haven't had enough time to expl explore react router I've spent the most time with nextjs so that's probably why I would pick it because I'm more familiar with it but remix now react router does
look very nice so I if I had the time to explore I probably would look at that as well and technically Astro also supports SSR so this is like the least opinionated piece of this video because I haven't built enough applications to really form an opinion here and personally I I don't like working with nextjs so that's why I'm not gung-ho recommending it for SSR because I know these other Solutions can offer similar things I just haven't had the time to work in them and and really honestly suggest them because I haven't gotten to work with them as much another one to mention though is tanack start which is essentially built on top of tanack router but it's currently in beta so I'm not going to mention it because it's in beta but it will be stable pretty soon and it'll be a contender here so that's it for this wishy-washy section where you're going to have to do your own research and uh pick and choose but you you'll see most people do recommend nextjs but I I'll tell you one of the reasons I am not the biggest fan of it is they introduced react server components probably like two years
before that feature was ever stable in react they are the only stable framework that supports react server components right now so there still is a lot of experimentation that needs to be done in the space by these other players um to really figure that out um because I just did not like the development experience with uh server components in nextjs okay and lastly is hybrid what if you have a a combination of all of these needs what if some of your pages should be statically generated but other ones need to be maybe a little bit interactive maybe you do have a heavy client side section of your app that is like a a stock dashboard or something like that and then maybe you have pieces of your app that need to be uh serers side rendered and and highly optimized for search engines then you would want a hybrid approach and pretty much all of these Frameworks that we're mentioning here support that hybrid approach as well essentially there are things you can do within the framework to say well this page should be statically generated or this page should be rendered but
hybrid apps
cached for two days before you need to uh re request the latest version of it or this page is always Dynamic and always needs to be server rendered and so if you fall into that boat where you just don't know the kind of the exact kind of app you're going to build be building you or you do know that you're going to be building apps of all types you want to go the hybrid approach and these all support that hybrid approach I will say this is definitely the least least opinionated section here because personally I like to make these decisions upfront instead of having the the framework kind of do it all for me and just expect that the framework's going to do the right thing when I need one rendering strategy over the other I'm probably just set in my ways because that's really the benefit of these all-inclusive Frameworks is they can decide and for you and you don't have to think about well should this be server rendered or should this just be run on the client so there we are the half highly opinionated half wishy-washy you're going to have to figure it out yourself but I probably gave you a little bit of info in terms of knowing
when and where and why to use these various tools when you want to create a react app so now let's finally talk about migrating from create react app if you have an app that you built with it a while ago or maybe you spun up one recently and didn't realize that it wasn't maintained or was going to be deprecated let's talk about your migration path there's a couple questions you need to answer first of all did you eject the webpack config so with create react app by default it hides all of the webpack configuration but if you ran mpm run eject that actually takes all of that configuration puts it into your codebase and now you're in charge of it and from there you can actually customize it and add more webpack settings now if that's the case I still recommend that you migrate to vit now you're going to have to do a little bit of work especially if you added other webpack plugins or highly customized that configuration you're going to have to do some work to convert that to a v config file and you'll see that pretty much everything you want to do like SVG loading or file optim iation or loading of specific file types or
migrating from CRA
changing your babo config has something in the v ecosystem already available as a plugin and if it doesn't it actually allows you to add Standalone Babble plugins or change configuration of existing plugins so I still recommend if you built something with create react app and you have a custom config I think you can still migrate to V now let's say you use create react app but you did not eject your config but you did use one of these tools that let you customize your web pack config so you might have come across these tools before there's things like crack out and also react app rewired essentially they allowed you to customize the webpack config without ejecting and if you built a react app in that way I still think your migration path is vit vit uses a very similar functionality to extend the underlying rollup and babble and Es build configs so everything you did to customize your config with those tools could be very easily migrated to do with vit as well and I think in this case your migration is actually going to be a lot SM smoother because you are probably
already using various plugins and you're likely going to be able to find those exact plugins for your V config as well and to actually show you some real world examples I found some large open source projects that were on create react app and actually migrated over to V the first is excal draw which is actually this app that I'm showing you right now if you didn't know excal draw is open source you can see there's a PR that was merged back in July of 2023 where they migrated from create react app to vit now their migration was very large because they also migrated from just to vest and so vest is a test runner from the same people that created V but it's essentially a dropin replacement for just they have a lot of just compatible apis and the reason a lot of people are switching to V and vest is because all of that custom webpack configuration that you used to have to do to get just working with typescript files and stuff like that vest takes care of all of that and so that's why this is a really big PR if you go through the files changed here you'll see first of all we have some environment variable changes
excalidraw vite migration example
because they're going from the react app environment variables to V app so there's a little bit of that but we'll also see this migration to vest so here you can see inside of every test file they're just importing vi from vest and then they're replacing just. spon with vi. spon and then a few other spots as well anytime they had just. function for creating mocked functions now it's vi.
function yeah and again scrolling through here it's kind of just the same stuff so it it seems like a big PR and you might want to make the same migration as well so if you have an app that's using create react app with jest this is probably a good example of how you can migrate and it's honestly it's funny for me to see they lit it's literally a drop in replacement it's just instead of just it's VI but this video is about V not vest so let me show you specifically their vit config because if you're migrating from a custom ejected webpack configuration your config might look a little bit like this it's going to be more complicated than just that base config you get with a generated vit application so you can see with the V config we can specify all of our build settings in their case they wanted to specify how they chunk files and you can do that here in your rollup options they added some other plugins so I talked about there's the react plug-in which lets you create react apps with feat you can see they also have this Checker plug-in this essentially just runs your eslint configs as part of the build process so things will fail if there's linting errors they're using
this SVG R plugin which converts svgs into react components that you can just import directly and use anywhere and then they also have this vit pwa plugin where they can specify all of their Progressive web app options because excal draw can be used offline if you at least loaded the app so there's a lot of progressive web app features here as well and so as you can see in this example their migration was fairly straightforward it's really just finding those plugins that do the things they were doing custom before and then just setting them up inside of their V config um so I think this is a really great example because it's a huge code base and they were able to successfully migrate from create react app and just to V and vest now I think it's Al worth mentioning that this PR happened back in July 2023 so I'm recording this in February of 2025 so that was like one and a half years ago and so that's also a testament to saying that like vit isn't new people in the JavaScript ecosystem have been using vit and migrating to vit for like over two years at this point so it's it's a tested
technology it's not like the latest and greatest thing it's the thing that most people in the front end are using these days now let's say you're migrating off of create react app but you didn't eject and you didn't want to use one of these tools to customize your web package fig the migration is so easy it's a drop in replacement it's so easy that I'm going to do it live right now I mean I know this is a recording but I found this app it's called react Redux real world example app it's from go thinkster so they have a project where they have this idea of a real world app and then they people submit it built in various stacks and so this is one of those builds but they use react and Redux but as you can see the last commit here was four years ago some of this code hasn't been touched in 9 years but if we take a look at the package ag. Json they are using react scripts which means they use create react app for this so to prove a point we're going to download this app and then just swap it out to use vit instead and it should be pretty painless so let's give it a go I'm going to grab the URL and clone it down here we go
full vite migration example
we'll head into that folder I'm going to go ahead and install dependencies and actually this this is four years ago so yeah we have we don't even have a package lock I guess this was before um I guess this couldn't have been is package lock only four years old I don't know but I'm going to use npm to install not pnpm so I'll do an npm install just to make sure it still works and then we'll migrate it to V look at all those deprecations awesome only 152 vulnerabilities but that means we can probably start the app up all right and it crashed uh FS events.at is not a function okay I we're we're it's four years ago I need to use an older version of node as well um it's like version 15 so I have NVM let's use that cool I'm going to start clean I know I could do npmc but I'm going to start clean okay now let's see if we can start it looking good so far it hasn't crashed uh can't
access property body a. response on oh okay so there's an API server that's running here and there's currently a DNS error to get this running I need to run the back-end server locally let me do that too okay took some noodling but I got the backend API running I've seen seed the database I now I'm now running that react Redux app you can see here that it has all the sample data essentially it's like a medium clone it's just like blog posts and it's a react Redux front end that talks to that Express API back end but what we're going to do is swap out react scripts which is create react app for V and see how easy it is so if we take a look at the codes we can see that we have an entry point so index.js is pulling in our app component and then mounting it on the page so first let's install vit as a Dev dependency now we need an entry point for vit and that's going to be the HTML file because that's what links to the index.js you can see here with their create react app they had a template so I'm going to move this index.html into
the root and then we can update some of the settings in here so get rid of this comment and then right here we want to point to that Javascript file that will get loaded in and bundled and such so right here we're just going to add a script so we point to Source SL index .js we going to give it a type of module looks good and then in this case we don't need the public URL because everything in the public folder is served up so I can just remove that okay this looks good so this is our entry point now all we need is a v config I'm going to import Define config from V and this will just export that cool and in this case we also need a plugin and we're going to need that react plugin so we'll install that the bejs plugin react react so we'll install that and now we can pull in that react plugin from there and then pass it to our plugins array and then we want to specify the port so here they have a server setting and
inside of here we can set that port to be 4100 great now Moment of Truth will it run okay we are getting an error whenever we did an install that says beat expects us to have node version 18 we tried 15 we tried 16 so let's actually downgrade to V version 5 our config will remain exactly the same cuz we're not doing anything crazy so we're going to downgrade to V version 5 use node version 15 or 16 and see if that fixes it so we're going to grab version five version five also is a minimum of 18 go on further back let's do V version 4 that seemed to be all right all right now let's try to run it didn't immediately crash let's see jsx syntax extension is currently is not currently enabled this used to be a thing we did so um we used to have react apps where we didn't name our files. jsx forgot about that okay that's confusing V let me do some research long story short
there are ways to enable it but the guidance is to just rename your files to jsx it makes it easier for the whole build process otherwise you need various plugins for ES build and for rollup so I'm just going to rename all the files to jsx and then uh we'll see if it runs I'm actually going to test out cursor and agent mode for this because it can generate commands to run from the command line so I'm going to say rename all. JS files in the SRC directory to jsx please I know why it's finding all the files yeah just just give me um give me a command that's what on okay so find every file that oh okay okay it finds all the files now that we have the list we're going to use a safe approach no need to be safe we have git just run a command that that renames them all you're right let's just rename them directly okay run the command Moment of Truth yeah look at that we got little react icons too sick okay now
we're going to close cursor and uh give this a try it starts up with no errors let's see as you can see from my overly lit face we've got errors let's see and that makes sense because we renamed it to jsx so let's do that and Global is not defined okay this was like possibly before promises were fully standardized what if I just pass in the global promise okay I don't want to have to update this whole code base just to get this working an index they also reference Global oh because it I think because it Imports it let's search the whole code base for Global promise equals global. promise just don't define that oh cool it's working um so yeah this browser stuff was just a warning then they were doing some weird stuff with global uh so we didn't have to make tiny code changes but the app is working let's click around sweet that's great it works fantastic all right to summarize if
you're migrating to V from create react app your config is going to be as simple as this now obviously if you have a much older code base that you haven't kept up with since then you're going to have other issues like node compatibility whatever and whatever else that has nothing to do with v itself in this particular instance we did have to use an older version of V because this code BAS is so old and it's doing weird things and depends on an old version of node um but as you can see even two versions ago vit was just as easy to configure um that was pretty much it of course we had to rename all of our files but really this is just good practice and that was about it yeah I guess we should test the build Let's test the build and then we'll call it a a migration done which honestly was not that bad I've I've done some migrations of sorts before and uh this was walk in the park compared to those yeah let's make sure it we can build it it builds it cool the other thing that vit has is a preview command where it essentially just runs a static server for your built
files let's just do this meat preview does run on a different port but it shows you that basically it's a simulation of of what will happen when you deploy these static files cool I don't think we have any tests yeah there's no tests this this this uh this script here was kind of just left behind so we don't have any tests to migrate okay so that was just a quick example of what it's like to migrate and as you can see it's it's literally just a matter of installing the right dependencies adding your config adding your entry point everything else should be fine as long as you're not doing other weird stuff but you can figure that out as well so like I mentioned if you had something built with create react app migrate to V and it it's essentially a drop- in replacement thank you so much for watching as you can see it's a bit of a mess out there there's a lot of different things you could be building and a lot of different choices you could make hopefully if you are building applications that fall into these categories I've given you some solid opinions that if you trust what I do and what I build you can go along with that um otherwise you can you can go down and explore these other routes as well now
conclusions / takeaways
the last thing I want to reiterate is literally every single thing I've shown you today except for nextjs is actually built on top of vit and so vit is the modern thing it's it's not the new hotness it's been adopted by so many things in the react space as well as uh the frontend framework space and other Frameworks that aren't react so choosing V is an easy choice if if the kind of applications that you're trying to build fall into those specific categories but as you can see you can do serers side rendering with vit via plugins which is how the react router framework does it or how tanack start does it as well okay that's it for this one if you have opinions about this or you think I'm wrong or maybe you want to provide some guidance on this SSR or hybrid path in the comments please uh leave a comment also if if there are any lingering questions about these types of apps or maybe you have an app in mind but you don't know what category it fits into leave it down in the comments I'll try to answer but I'm sure people watching the video can help out as well okay that's it for this one I'll see you in
thanks
Quote it with credit and a link. Quoting Syntax