Tech StudioCoffee LabSwitch between Simon's Tech Studio and Coffee Lab.
Loading blog…
Part 1: Setting Up a Modern Next.js Project. | Simon Mwangi
development•
3 min read
Part 1: Setting Up a Modern Next.js Project.
This blog post will guide you through setting up a robust and modern Next.js project, incorporating best practices and essential tools for a smooth development experience.
Building a modern Next.js application involves more than just throwing components together. A well-structured project with the right tooling can significantly boost productivity, maintainability, and collaboration. This guide walks you through setting up a robust Next.js project, incorporating essential tools and best practices.
Preparing the Environment:
Before diving in, ensure you have the following installed:
Node.js: An active LTS version is recommended. (We'll lock this down later.)
Yarn: My preferred package manager for this setup. You can use npm if you prefer, but the commands will differ slightly.
VS Code (or your IDE of choice): A good code editor is essential. I'll be referencing VS Code throughout this guide.
Project Initialization: Laying the Foundation
1. Create the Next.js app:
Code snippetsh
npx create-next-app@latest
Answer the prompts. Here's a sample configuration:
Code snippetsh
✔ What is your project named? … coffee-roasting-lms
✔ Would you like to use TypeScript? … Yes
✔ Would you like to use ESLint? … Yes
✔ Would you like to use Tailwind CSS? … Yes
✔ Would you like your code inside a `src/` directory? … Yes
✔ Would you like to use App Router? (recommended) … Yes
✔ Would you like to use Turbopack for `next dev`? … Yes
✔ Would you like to customize the import alias (`@/*` by default)? … Yes
✔ What import alias would you like configured? … @/*
Shadcn/UI is a set of beautifully designed, accessible components and a code distribution platform. You have full control to customize and extend the components to your needs.
Code snippetsh
npx shadcn@latest init
Follow the prompts to configure Shadcn UI.
3. Component Organization:
For better organization, I recommend adjusting the components.json file generated by Shadcn UI to match your project's folder structure.
Locking your Node.js and package manager versions prevents inconsistencies across development environments.
Run the linter, you should get a message like this:
✔ No ESLint warnings or errors
Done in 1.30s.
If you encounter any errors, ESLint will help you clearly understand what they are. If you come across a rule you don't agree with, you can easily disable it in the "rules" section by setting it to 1 (warning) or 0 (ignore), like this:
"rules": {
"no-unused-vars": 0, // As example: Will never bug you about unused variables again
}
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
echo '🏗️🚀 Pre-flight check: Formatting, linting, and building before liftoff!'
# Check Prettier standards
yarn check-format ||
(
echo '🤢🤮 CODE CRIME ALERT! 🤮🤢
Your formatting is an absolute disgrace. Run `yarn format`, stage the changes, and try again.';
false;
)
# Check ESLint Standards
yarn check-lint ||
(
echo '😤💀 LINT POLICE SAYS NO! 💀😤
ESLint caught some bad code. Fix the errors above, commit again, and don’t make me do this twice!'
false;
)
# Check TypeScript standards
yarn check-types ||
(
echo '🤡😂 TYPE CHECK FAIL DETECTED 😂🤡
That’s not even JavaScript—it’s just chaos! Read the errors above and fix your mess.';
false;
)
# If everything passes... Now we can build
echo '🤔🤔🤔 Hmm... Looks clean so far. Let’s see if it builds. 🚀'
yarn build ||
(
echo '❌👷♂️ CALL THE ENGINEERS! ❌
Build failed. Check the logs above and try again.';
false;
)
# If everything passes... Now we can commit
echo '✅🎉 SHIP IT! 🎉✅
Everything checks out. Committing now like a responsible dev.'
Commitlint: Enforcing Commit Message Standards
To enforce commit message conventions, install CommitLint:
At this stage we will be making a commit with message build: implement storybook
VS Code Configuration
Now that we’ve implemented ESLint, Prettier, and Storybook, we can set up Visual Studio Code (VS Code) to run them automatically. Create a directory called `.vscode` in the root of your project, and inside it, add a file named `settings.json`. This file will contain project-specific settings that we can share with our team through the code repository. In `settings.json`, we will add the following values: `.vscode/settings.json`
Let's set up an environment for debugging our application in case we run into any issues during development. Inside of your .vscode directory create a launch.json file: launch.json