DEV Community

Cover image for Host Lovable.dev Project on github pages 😺
Atul Kushwaha
Atul Kushwaha

Posted on • Edited on

Host Lovable.dev Project on github pages 😺

Deploying a Lovable.dev Project to GitHub Pages

link to the blog to get free custom .me domain name Free custom domain for your projects πŸ˜‰

Here is the link to my portfolio, generated by lovable.dev and hosted on GitHub Pages


Prerequisites

Before we begin, ensure you have the following:

  1. Node.js (version 18 or higher) installed on your system.
  2. Basic knowledge of Git and GitHub.

Step 1: Connect lovable.dev with GitHub

connect github

  • Click View on GitHub.
  • Clone this private project locally on your machine.
  • Open a terminal in your cloned repository location. First, we are going to remove all Git files. For Windows, type:
Remove-Item -Recurse -Force .git
# Check if Git files still exist
git status
Enter fullscreen mode Exit fullscreen mode
  • This will remove all Git-related files from your project.
  • Now we can try running the project locally:
npm install       # Install all dependencies
npm run build
npm run dev
Enter fullscreen mode Exit fullscreen mode

6.Make any changes to the code if needed.


Step 2: Create a New Repo for GitHub Pages and Update Config

  • Create a new repository, say coderatul-portfolio, on GitHub.
  • Clone this newly created repository to your machine.
  • Copy and paste all files from your original project (where Git was removed) to this new repo coderatul-portfolio.
  • You may now delete the initially cloned repository, as we have all source code where we need it.

Update vite.config.ts

The base property in the Vite configuration file (vite.config.ts) must be set to the repository name for GitHub Pages. This ensures that all asset paths are correctly resolved.

Example:

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import path from "path";
import { componentTagger } from "lovable-tagger";

export default defineConfig(({ mode }) => ({
  server: {
    host: "::",
    port: 8080,
  },
  plugins: [
    react(),
    mode === 'development' &&
    componentTagger(),
  ].filter(Boolean),
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  base: '/coderatul-portfolio/' // Replace with your GitHub repo name
}));
Enter fullscreen mode Exit fullscreen mode

Step 3: Push Code to GitHub and Set Up Workflow via GitHub Actions

  • Push the changes to your repository say coderatul-portfolio here:
git status
git add .
git commit -m "adding project"
git push -u origin main
Enter fullscreen mode Exit fullscreen mode
  • Grant access for workflow: Visit https://github.com/<your-username>/<your-repository-name>/settings/actions, scroll down, make the necessary changes, and save.

permission

  • In your repository, go to Settings > Pages

t0

  • Select GitHub Actions
  • Then select GitHub Pages Jekyll and click Configure

t1

  • Edit the workflow

t2

Modify workflow.yaml as follows:

name: Deploy to GitHub Pages

on:
  push:
    branches:
      - main

permissions:
  id-token: write 
  contents: write 
  pages: write    

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18 

      - name: Vite GitHub Pages Deployer
        uses: skywarth/[email protected]
        with:
          public_base_path: /coderatul-portfolio/  # Replace with your repository name
          build_path: ./dist
          install_phase_node_env: dev
          build_phase_node_env: production
          package_manager: npm
          artifact_name: github-pages
          debug_mode: false
          working_path: ./
Enter fullscreen mode Exit fullscreen mode

Step 4: Verify the Deployment

  • Make appropriate changes, paste the modified workflow.yaml, commit it, and the workflow will start under the Actions tab.
  • Under Settings > Pages, you’ll see a live link to the deployed project.

What is a Workflow?

A workflow automates the process: any time you push code, GitHub Actions will automatically build and deploy your project. This is part of CI/CD.


Common Issues and Fixes

1. Blank Page After Deployment

  • Make sure the base property in vite.config.ts is correctly set to /repository-name/.
  • Clear browser cache or use incognito mode.

2. 403 Permission Errors

  • Ensure the GITHUB_TOKEN in your workflow has the correct permissions:
permissions:
  id-token: write
  contents: write
  pages: write
Enter fullscreen mode Exit fullscreen mode

3. Asset Paths Not Resolving

  • Double-check the base property in vite.config.ts and ensure it matches your repo name.

Conclusion

Deploying a lovable.dev project to GitHub Pages is simple with the right setup. By setting the base path in vite.config.ts and automating deployment using GitHub Actions, you can publish your project effortlessly.

Top comments (13)

Collapse
 
poolshark profile image
Flo Ragossnig

A quick update. I have no clue if Github changed the default pages route now but according to their docs you must name your repo <username>.github.io. This will automatically be your base route (so https://.github.io). Therefore, in the vite.config.ts, the base path must be

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import path from "path";
import { componentTagger } from "lovable-tagger";

export default defineConfig(({ mode }) => ({
  server: {
    host: "::",
    port: 8080,
  },
  plugins: [
    react(),
    mode === 'development' &&
    componentTagger(),
  ].filter(Boolean),
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  base: '/' // Since this will be the base directory
}));
Enter fullscreen mode Exit fullscreen mode

Additionally, you need to change the base path destination in the workflow.yaml file accordingly


on:
  push:
    branches:
      - main

permissions:
  id-token: write 
  contents: write 
  pages: write    

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18 

      - name: Vite GitHub Pages Deployer
        uses: skywarth/[email protected]
        with:
          public_base_path: /  # This is the base
          build_path: ./dist
          install_phase_node_env: dev
          build_phase_node_env: production
          package_manager: npm
          artifact_name: github-pages
          debug_mode: false
          working_path: ./
Enter fullscreen mode Exit fullscreen mode
Collapse
 
coderatul profile image
Atul Kushwaha

my repo name is coderatul.github.io and i set base path to this only

in workflow : public_base_path: /coderatul.github.io/
and in vite config file: base: '/coderatul.github.io/'

and it works maybe you forgot : /repo name/ (the slashesh)

anyway i went through your github and yours seems working with base as / so thanks for commenting this people facing issue might get it right with base as /

Collapse
 
srijan-xi profile image
Srijan Kumar

Can you a video tutorial for this

Collapse
 
coderatul profile image
Atul Kushwaha

on whihc platform should i upload it any recommendation ?

Collapse
 
daros_neochmosis profile image
Daros Neochmosis

everything done properly but still getting 404

Collapse
 
coderatul profile image
Atul Kushwaha
Collapse
 
daros_neochmosis profile image
Daros Neochmosis • Edited

Yes, that fixed the problem bro, problem caused because I didnt change the workflow properly!
thanks again and keep up the good work sharing such projects

Thread Thread
 
coderatul profile image
Atul Kushwaha

thanks for your kind words and appreciating

Thread Thread
 
daros_neochmosis profile image
Daros Neochmosis

Your most welcome, have you ever tried a second page or I guess probably need a new github acc for that

Collapse
 
daros_neochmosis profile image
Daros Neochmosis • Edited

Thank you for your quick reply, I think I tried it before writing here but I will try again later and get back to you

Collapse
 
madhurima_rawat profile image
Madhurima Rawat

Your portfolio looks good ✨️ Looking forward to custom domain article, would be helpful

Collapse
 
coderatul profile image
Atul Kushwaha

a blog has been uploaded reagarding this blog

Collapse
 
madhurima_rawat profile image
Madhurima Rawat

Thanks for uploading! I read the blog β€” it’s really informative.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.