Part 30: Building a Hybrid Shop Website with Next.js
[Pages] Next Shop: Setup

In this part of our course, we'll embark on building a more sophisticated application using Next.js. Our project will be an online shop specializing in indoor plants. This shop will utilize both static pages and server-side rendering (SSR), making it a hybrid application. Let's dive into the features and setup of this exciting project.
Application Features
Key Functionalities
Product Grid: Showcase a collection of products with images.
Product Details: Provide detailed information on selected items.
User Authentication: Allow users to sign in and manage their shopping carts.
Shopping Cart: Enable users to add products to their cart and view order summaries.
Project Setup
1. Creating a New Next.js Project
We'll initiate our project using the Create Next App tool, which simplifies the setup process by providing a ready-to-use project structure.
npx create-next-app next-shopThis command will generate a new folder named next-shop, which contains all the essential files and dependencies to kickstart our project. Let's open this folder in our code editor, such as Visual Studio Code.
2. Exploring the Initial Project Structure
Upon opening the project, you'll notice several key files and directories:
package.json: Lists dependencies likenextandreact, along with scripts for development, building, and starting the project. It also includeseslintin thedevDependenciesfor code quality checks.pagesDirectory: Contains theindex.jsfile for the home page and_app.jsfor custom app configuration. There's also anapifolder initially, which we can remove for now as we'll cover API routes later.stylesDirectory: Includes aglobals.cssfile for global styles andHome.module.cssfor component-specific styles using CSS modules.publicDirectory: Contains default images likefaviconand a logo, which we can replace with our own assets later.Configuration Files: Includes
.gitignorefor version control exclusions andnext.config.jsfor Next.js-specific settings.
3. Cleaning Up the Initial Setup
Before we start building our shop, let's tidy up the initial setup:
Remove unnecessary files such as the
vercel.svgandHome.module.css.Simplify the
index.jsfile by deleting the boilerplate JSX and adding our custom home page content.
Here's a simplified version of our index.js:
// next-shop/pages/index.js
import Head from 'next/head';
function HomePage() {
return (
<>
<Head>
<title>Next Shop</title>
</Head>
<main>
<h1>Next Shop</h1>
</main>
</>
);
}
export default HomePage;4. Running the Application
To see our basic setup in action, run the development server:
npm run devOpen the provided URL in a web browser, and you'll see our minimalist home page with the title "Next Shop."
List of Deleted Files
During the cleanup, we removed the following files:
pages/api/hello.js: An initial API route example.public/vercel.svg: A default logo image.styles/Home.module.css: Styles specific to the initial home page.public/next.svg: Another default image.pages/_document.js: An optional file for customizing the document structure.jsconfig.json: A configuration file that was not necessary for our current setup.
Conclusion
With our project set up and unnecessary files removed, we're ready to start building our shop's functionality. In the next steps, we'll incorporate advanced Next.js features like static site generation, server-side rendering, and more. This journey will enhance your skills in creating robust and dynamic web applications. Stay tuned as we continue to develop our online plant shop!
Last updated