Lädt...


🔧 From Local to Live: How to Deploy Your React Application using Netlify.


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

You've spent hours perfecting your React app, and now it's time to share it with the world. Building a React app is one thing, but getting it live? That's the magic moment✨. Fortunately, with Netlify, taking your project from your laptop to the world is a breeze. Whether you're a seasoned developer or new to deployment this guide will walk you through every step of launching your React app—no headaches, just results. Ready to make your app live in minutes? Let’s make it happen!

There are several ways to deploy on Netlify but in this guide we'll be looking at two methods- Deploy with Git and Drag and Drop.

Step 1: Preparing your React App.

Before deploying, you need to ensure your React app is ready for production. You'll want to:

1. Run a Final Test: Make sure your app works as expected locally by running:
npm run dev
If it was created with Vite.
npm run start
If it was created with Create-React-App.

I recommend creating with Vite.

This command launches your app in development mode. Open http://localhost:5173 or http://localhost:3000 in your browser to see how it performs.

2. Build for production: To get your app ready for the web, create a production build:
npm run build

This will bundle your app into optimized static files in a build / dist folder, ready for deployment.

Do well to make sure your project is on github.

Step 2: Setting up Netlify

1. Sign Up for Netlify: Head over to Netlify's website and sign up for a free account if you don’t have one already. You can use your GitHub or GitLab account to sign up.

2. Create a New Site: Once logged in, click on the "Add New site" button.

Screenshot (384)

Deploy with Git.

To deploy with your Git click on "Import an existing project"

Step 1: Connecting Your Git Repository

1. Choose Your Git Provider: Select your Git provider (GitHub, GitLab, or Bitbucket) where your project is hosted.

Screenshot (385)

2. Authorize Netlify: Netlify will ask for permission to access your repository. Authorize it, and you’ll be redirected back to the dashboard.

3. Select Your Repository: Choose the repository that contains your React app project. Netlify will scan your project and automatically detect that it’s a React app.

Step 2: Configuring Your Build Settings

1. Set Build Command and Publish Directory: In the build settings, Netlify typically fills in the correct fields for you:

  • Build Command: npm run build
  • Publish Directory: build/ or dist/

Screenshot (386)

If these fields aren’t filled, simply enter the commands above. These settings will ensure Netlify builds and deploys your app properly.

2. Deploy Site: Click on “Deploy site”, and Netlify will start building and deploying your React app.

Step 3: Your Site is Live!

Once the deployment process finishes, Netlify will provide you with a live URL for your React app project. You can click on the link to view your live site.

  • Custom Domain: If you’d like, you can also change your site name to a custom domain through Netlify. Click on "Site Configuration"

Screenshot (388)

Scroll down a bit further till you see "Change site name" click that and edit your site name to any of your choice as long as it's available.

One of the best features of Netlify is continuous deployment. Anytime you push a change to your Git repository, Netlify will automatically rebuild and redeploy your app. This keeps your site up to date with the latest version of your app.

Deploy using Drag and Drop.

Screenshot (384)

To deploy using drag and drop click on "Deploy Manually"

Drag your dist or build folder and drop it in the circle or you can browse to upload the folder.

Screenshot (390)

After dropping, clicking on "Open Production Deploy" takes you to your live link.

To enable continuous deployment after using Deploy manually you need to navigate to deploy settings to link your repository.

Options settings

Deploy settings

Click on "Link repository" and follow the steps.

Bonus Feature.

Redirects and Rewrites: Ever deployed your react app on Netlify and when you try navigating to a page that exists on your local host you get a 404 error?

404 error

Netlify allows you to easily set up redirects and rewrite rules using a simple _redirects file in your project.

In your editor(VsCode) add a _redirects file in your public folder and add this in it.

/* /index.html 200

Image description
This solves the issue.

Conclusion🎉.

Deploying your React app doesn’t have to be complicated, especially with a platform like Netlify. With just a few steps, your app is live and accessible to the world, and with continuous deployment, future updates are a breeze. Now that you’ve gone from local to live, you can focus on what matters most—building great features for your users!

Happy Coding!🚀

...

🔧 From Local to Live: How to Deploy Your React Application using Netlify.


📈 53.45 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge: Photo Gallery with React and Netlify Image CDN


📈 39.04 Punkte
🔧 Programmierung

🔧 How to Deploy Your React App Using Cloudflare Pages, Vercel, and Netlify


📈 38.61 Punkte
🔧 Programmierung

🔧 Page Views Counter: Netlify Dynamic Site Challenge using Netlify Blobs


📈 37.13 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge: Web Voyager, a website screenshot service using Netlify Blob storage.


📈 37.13 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge : Building a Dynamic Image Gallery with Netlify Image CDN


📈 33.09 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge - Netlify Image CDN to transform an image Gallery


📈 33.09 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge - Netlify Image CDN to transform an image Gallery


📈 33.09 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge - Netlify Image CDN to transform an image Gallery


📈 33.09 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge : Building blob playground with Netlify Blob


📈 33.09 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge Submission: Visual Feast-- Netlify CDN Cache-Control Implementation


📈 33.09 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge Submission: Dynamic Image Gallery with Netlify Image CDN Visual Feast


📈 33.09 Punkte
🔧 Programmierung

🔧 Netlify Dynamic Site Challenge Submission: Dynamic Image Gallery with Netlify Image CDN Visual Feast


📈 33.09 Punkte
🔧 Programmierung

🔧 How to Manually Deploy a React and TypeScript Project on Netlify


📈 31.77 Punkte
🔧 Programmierung

🔧 Deploy static site manually using Netlify in 2024


📈 29.86 Punkte
🔧 Programmierung

🔧 How to Easily Deploy Your Vue.js Project on Netlify for Free


📈 28.61 Punkte
🔧 Programmierung

🔧 How to Create a Custom Deploy (Vercel/Netlify) Button for your Sanity Project


📈 28.61 Punkte
🔧 Programmierung

🔧 Programmatically deploy your GitHub Repo on Netlify


📈 28.61 Punkte
🔧 Programmierung

🔧 How to Deploy your Static Site to Netlify


📈 28.61 Punkte
🔧 Programmierung

🔧 Netlify vs Vercel vs Surge | The best platform I use to deploy your projects 🤔?!


📈 28.61 Punkte
🔧 Programmierung

🔧 Deploy your bolt.new app to Netlify


📈 28.61 Punkte
🔧 Programmierung

🔧 Creating an OG image using React and Netlify Edge Functions


📈 26.54 Punkte
🔧 Programmierung

🔧 How to deploy a Node.js Express app on Netlify (2024)


📈 25.82 Punkte
🔧 Programmierung

🔧 Learn Use Express for Backend Simple WebService and Deploy for Free in netlify platform


📈 25.82 Punkte
🔧 Programmierung

🔧 From Local Files to Live: Deploy Your Static Website Using Azure Storage


📈 25.64 Punkte
🔧 Programmierung

🔧 Step-by-Step Guide to Deploying Your React App on Netlify


📈 25.29 Punkte
🔧 Programmierung

🔧 Deploy a Django and React application using Render and integrate AWS S3


📈 24.58 Punkte
🔧 Programmierung

🔧 Deploy React.js application using AWS S3 & GitLab pipelines for automatic deployment 2024


📈 24.58 Punkte
🔧 Programmierung

🔧 Deploy React.js application using AWS S3 and use GitLab pipelines for automatic deployment 2024


📈 24.58 Punkte
🔧 Programmierung

🔧 Deno Deploy: Deploy a React App


📈 24.49 Punkte
🔧 Programmierung

🔧 This Week In React #185: React Conf, React Query, refs, Next.js after, mini-react...


📈 23.8 Punkte
🔧 Programmierung

🔧 This Week In React #185: React Conf, React Query, refs, Next.js after, mini-react...


📈 23.8 Punkte
🔧 Programmierung

🔧 Show Your Recently Played Song using Netlify Functions and Last.fm


📈 23.39 Punkte
🔧 Programmierung

🔧 Easy guide to solving 404 after deploying react code on vercel/netlify.


📈 22.49 Punkte
🔧 Programmierung

matomo