Setting up webapps can be time consuming, particularly when the goal is to build a quick proof of concept of something. One challenge I find is that I spend most of my time setting up the project, leaving little time to actually build the functionality on top of it.
I’ve recently been exploring Next.js as a framework for creating full stack applications easily and I’ve found a way of quickly setting up a new project by combining it with Tailwind CSS for styling.
From my exploration I’ve found a set of tools that provide a good baseline for building web apps, they are:
With all that in mind, lets setup a new project.
To setup the project we are going to use create-next-app
, which is a tool that easily allows bootstrapping new Next.js applications. create-next-app
has a few CLI flags we can pass to streamline the process.
To get started open a terminal and cd
to where you keep your projects, for example cd ~/projects
then copy and paste the below command into the terminal
pnpm create next-app \
--typescript \
--tailwind \
--eslint \
--app \
--src-dir \
--import-alias "@/*"
The above command sets up Typescript and Tailwind by default and uses the new app router. When ran you will be prompted to enter a project name
? What is your project named? › my-app
After the command finishes, open the project in vscode with
code my-app
Prettier takes a lot of the manual work out of formatting code by automatically formatting code when you save. Its really quick to setup and saves heaps of time.
pnpm i prettier eslint-config-prettier
.prettierignore
.next
node_modules
pnpm-lock.yaml
.prettierrc.json
config file for Prettier
{}
.eslintrc.json
{
"extends": ["next/core-web-vitals", "prettier"]
}
format
NPM script
{
"scripts": {
"format": "prettier --write ."
}
}
VSCode has a concept of a per project workspace, which allows you to store editor configuration in the repo, which is useful if multiple people contribute to the code (as everyone will have the same base config). It also has some handy features such as defining a set of recommended extensions to prompt the user with when they open the project.
.vscode/settings.json
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
.vscode/extensions.json
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss"
]
}
create-next-app
will automatically generate some boilerplate, I find it easiest to delete it, so you can start with a blank slate. Luckily deleting the boilerplate is really quick.
rm public/*
src/app/globals.css
with
@tailwind base;
@tailwind components;
@tailwind utilities;
src/app/page.tsx
with
export default function Home() {
return <main></main>;
}
tailwind.config.js
with
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {},
plugins: [],
};
With all the configuration now done, everything is ready to go to build an app. The app can be started with pnpm dev
. Once ran you should see a blank screen, add some content to the src/app/page.tsx
file and you should see it reflect on the page.