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:
- Node.js (version 18 or higher) installed on your system.
- Basic knowledge of Git and GitHub.
Step 1: Connect lovable.dev with 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
- 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
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
}));
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
- Grant access for workflow:
Visit
https://github.com/<your-username>/<your-repository-name>/settings/actions
, scroll down, make the necessary changes, and save.
- In your repository, go to Settings > Pages
- Select
GitHub Actions
- Then select
GitHub Pages Jekyll
and clickConfigure
- Edit the workflow
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: ./
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 invite.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
3. Asset Paths Not Resolving
- Double-check the
base
property invite.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)
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 thevite.config.ts
, the base path must beAdditionally, you need to change the base path destination in the
workflow.yaml
file accordinglymy repo name is
coderatul.github.io
and i set base path to this onlyin 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/
Can you a video tutorial for this
on whihc platform should i upload it any recommendation ?
everything done properly but still getting 404
try this dev.to/poolshark/comment/2nhik
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
thanks for your kind words and appreciating
Your most welcome, have you ever tried a second page or I guess probably need a new github acc for that
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
Your portfolio looks good β¨οΈ Looking forward to custom domain article, would be helpful
a blog has been uploaded reagarding this blog
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.