LazyCodet

a

13:00:12 18/5/2024 - 0 views -
Programming

Cloudflare Pages - Deploy your project easily & FREE

Cloudflare Pages is so amazing to me.  Normally, when we deploy a frontend, we can deploy it in the VPS or github/gitlab pages (public repository).

​But Cloudflare pages are free even for private repositories. You can see the price of Cloudflare Pages services below Image 1:

Cloudflare pages pricing (5/18/2024)
Image 1: Cloudflare pages pricing (5/18/2024)

Let's get cracking

1. ​Sign in to Cloudflare

​2. In the left sidebar, Choose the Workers & Pages option.

​3. Choose the Pages tab and click Connect to Git button Image 2 

The steps to Connect to Git
Image 2: The steps to Connect to Git

4. You can choose GitHub or GitLab to connect

​5. You should authorize and specify a repository Image 3

Install & Authorize Cloudflare Pages
Image 3: Install & Authorize Cloudflare Pages

6. You can do some steps by the guide until step 2:Set up builds and deployments

​In my case, My project uses Vite so I set the Build command as "npm run build" and the Build output directory as "dist" Image 4

Set up builds and deployments
Image 4: Set up builds and deployments

7. After building processing is finished Image 5

 Built and deployed
Image 5: Built and deployed


8. I can access my website (In my case, I'm waiting for about 10 seconds, and my website can be accessed) Image 6

Accessing my website after built
Image 6: Accessing my website after built

CI/CD

​With this approach, when you update your code and push it to Github/Gitlab. It will trigger Cloudflare Pages that pull the project to build and deploy automatically

​Easy to work with your team

​With this approach, when you update your code in another branch and push it to Github/Gitlab. It will create a new domain to review with your members.

​For example, I create a new branch named test, update my code, and push the branch to the Repository. Cloudflare triggered and deployed my branch in subdomains like Image 7 & Image 8 

The new branch is deployed
Image 7: The new branch is deployed


I can access the website for the new branch
Image 8: I can access the website for the new branch

Conclusion

​With the Cloudflare Pages, You can see I can deploy my website to the Internet easily. Let's deploy your project now!

​References

​https://www.youtube.com/watch?v=MTc2CTYoszY