Mega Prompt: Vite/React to Next.js Conversion for SEO
🤖 Mega Prompt: Vite/React to Next.js Conversion for SEO
Objective
Transform a React/Vite project into a Next.js application for enhanced SEO and performance. The final product must retain all original design and functionality while implementing server-side rendering (SSR) or static site generation (SSG) for optimal crawlability.
Target Audience
Web developers and engineers looking to improve a website's SEO using a modern framework like Next.js.
SEO Keywords
Next.js conversion, Vite to Next.js migration, SEO-friendly websites, React SEO, server-side rendering (SSR), static site generation (SSG), technical SEO, AI-powered web development.
Instructions
Project Setup
Create a new Next.js project with the pages router, TypeScript, and Tailwind CSS.
Component Migration
Transfer all reusable components from the /src/components/ directory in the Vite project to the new /components/ directory in Next.js.
Page Conversion & Server Rendering
- For each screen or route, create a matching file in /pages/.
- Implement getStaticProps() for static marketing or content pages to enable SSG.
- Use getServerSideProps() for pages with dynamic or API-driven data to enable SSR.
- Ensure all primary page content is rendered on the server, viewable in "View Source" without JavaScript.
Routing & Links
- Replace all instances of react-router-dom with Next.js's <Link> component.
- Maintain clean, SEO-friendly URLs that mirror the existing structure (e.g., /industry/sub-industry).
Technical SEO Implementation
- Integrate the <Head> component on every page.
- Dynamically populate <title> and <meta name="description"> tags from the existing content.
- Ensure all content is accessible to search engine crawlers.
Functionality & Styling
- Preserve all existing interactivity and component functionality after hydration.
- Ensure all styling, including Tailwind and CSS modules, works seamlessly.
Output & Verification
- Provide the final, fully converted project code.
- Document the new folder structure in a clear tree view.
- Verify that the homepage's HTML contains all key content and that interactive elements still work after loading.
Important Note
This mega prompt is highly effective, but it's not foolproof. It works correctly about 99% of the time, but there can be exceptions based on your project's specific configuration.
Always back up your code! Before running a large-scale migration like this, make sure you have a complete backup of your project or know how to revert the changes using version control like Git (e.g., `git reset --hard` or `git checkout .`).
How to Use This Mega Prompt
This prompt is designed to be used with a variety of AI-powered coding assistants and tools. The goal is to provide the AI with a comprehensive set of instructions to perform the migration accurately.
Supported Tools
You can use this prompt with a wide range of AI coding assistants, including:
- Google's AI tools like Jules
- OpenAI's Codex and its integrations
- Modern IDEs with AI capabilities like Visual Studio, Cursor, Trae, etc.
Usage Steps
- Copy the Prompt: Click the copy button on the prompt box above to copy the entire text to your clipboard.
- Open Your AI Tool: Go to your preferred AI coding assistant or IDE.
- Paste and Run: Paste the complete prompt into the chat or command input field of the AI tool. The AI should then begin the process of analyzing your code and suggesting the necessary changes for the migration.
- Review and Apply: Carefully review the changes suggested by the AI. Apply them incrementally and test your application at each step to ensure everything is working correctly.
Why Migrate from Vite/React to Next.js?
While Vite is an incredibly fast build tool and React is a powerful library for building user interfaces, a pure client-side rendered (CSR) React app has significant SEO limitations. Next.js provides a robust framework that solves these challenges and offers additional benefits for production-ready applications.
Superior SEO with Server-Side Rendering (SSR) & Static Site Generation (SSG)
A standard Vite/React project relies on JavaScript to build the page content in the user's browser. This is a problem for search engine crawlers, which may struggle to properly index all your content. Next.js, on the other hand, pre-renders the HTML on the server, sending a fully-formed page to the browser. This ensures that crawlers see all the content, leading to better indexing and higher search rankings.
Built-in Performance Optimizations
Next.js comes with out-of-the-box features that improve site speed, a critical ranking factor for Google. The framework automatically handles code splitting, image optimization with the <Image> component, and prefetching of links, all of which contribute to faster page loads and a better user experience.
Simplified Routing and API Routes
Next.js uses a file-system based routing system that eliminates the need for manual setup with libraries like react-router-dom. This simplifies development and ensures clean, SEO-friendly URLs. Additionally, Next.js allows you to create API endpoints directly within your project, enabling full-stack capabilities without needing a separate server.
Hybrid Approach for Flexibility
Next.js allows you to choose the best rendering strategy for each page. You can use SSG for static marketing pages (e.g., about, contact) for maximum speed, and SSR for dynamic content (e.g., e-commerce product pages), providing the best of both worlds.
A Deeper Dive into the Migration Process
Project Planning & Strategy 🗺️
Before you write a single line of code, take a step back and perform a detailed audit of your existing Vite/React project. Start by mapping out all your existing routes and their corresponding components. This is a critical step to avoid missing any pages during the migration. Identify which pages are static (like "About Us" or "Contact") and which are dynamic (like a blog post or a product page). This will help you decide whether to use SSG or SSR for each route, a core decision in Next.js. Also, make note of any client-side-only functionality, such as components that rely on browser APIs.
Code Refactoring & Optimization ⚙️
Next.js works best with modern React practices. As you migrate, take the opportunity to refactor any older class components into functional components with hooks. This aligns your project with the current standard and makes the codebase cleaner.
A major change is moving from client-side data fetching to server-side fetching. Convert your useEffect hooks that fetch data from an API into getServerSideProps or getStaticProps. This ensures the data is included in the initial HTML, which is a major win for SEO. For example, instead of an empty div that gets filled with data after a network request, your page will load with all the content already there.
Finally, place all your static assets like images, fonts, and CSS files in the new Next.js /public directory. Update all your paths to be root-relative. For instance, an image at src/assets/logo.png will now be at /logo.png.
Post-Migration & Deployment 🚀
Once the code is converted, testing is crucial. Verify that your pages render correctly on the server by using a tool like curl or by viewing the page source. Look for a fully-formed HTML document, not just an empty root div. Check for any hydration errors in the browser console, which can happen if server-rendered content doesn't match the client-side version.
For deployment, the process is straightforward thanks to platforms like Vercel and Netlify. Both automatically detect a Next.js project and handle all the necessary configurations. You simply connect your Git repository, and the platform will build, optimize, and deploy your site, giving you a smooth transition to a production environment.