Boilerplate used - Github
Developer experience first:
- โก Next.js for Static Site Generator
- ๐ฅ Type checking TypeScript
- โ Strict Mode for TypeScript and React 18
- ๐ Linter with ESLint (default NextJS, NextJS Core Web Vitals, Tailwind CSS and Airbnb configuration)
- ๐ Code Formatter with Prettier
- ๐ฆ Husky for Git Hooks
- ๐ซ Lint-staged for running linters on Git staged files
- ๐ Lint git commit with Commitlint
- ๐ฆบ Unit Testing with Jest and React Testing Library
- ๐งช E2E Testing with Cypress
- ๐ก Absolute Imports using
@
prefix - ๐ VSCode configuration: Debug, Settings, Tasks and extension for PostCSS, ESLint, Prettier, TypeScript, Jest
- ๐ค SEO metadata, JSON-LD and Open Graph tags with Next SEO
- โ๏ธ Bundler Analyzer
- ๐ฑ๏ธ One click deployment with Vercel or Netlify (or manual deployment to any hosting services)
- ๐ Include a FREE minimalist theme
- ๐ฏ Maximize lighthouse score
Built-in feature from Next.js:
- โ Minify HTML & CSS
- ๐จ Live reload
- โ Cache busting
- Minimal code
- SEO-friendly
- ๐ Production-ready
- Node.js 14+ and npm
Run the following command on your local environment:
git clone --depth=1 https://github.com/ixartz/Next-js-Boilerplate.git my-project-name
cd my-project-name
yarn
Then, you can run locally in development mode with live reload:
yarn dev
Open http://localhost:3000 with your favorite browser to see your project.
First things first, create your .env file by running the following command:
$ cp .env.example .env
Then you need to copy the environment values from the docker-compose.yml file to fill in the default values of the DATABASE_URL variable on .env file:
DATABASE_URL="postgresql://user:pass@host:5432/dbname"
To get your host ip, simply inspect all your docker containers and copy the one corresponding to your db
$ docker inspect --format='{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -q)
By completing the filling process on the .env file, run the following command to run the migrations over your database:
$ npx prisma migrate dev
(Optional) To populate the database run this:
$ npm run seed
To visualize the database using prisma studio:
$ npx prisma studio
.
โโโ README.md # README file
โโโ __mocks__ # Mocks for testing
โโโ .github # GitHub folder
โโโ .husky # Husky configuration
โโโ .vscode # VSCode configuration
โโโ prisma # Database migration folder
โ โโโ migrations # migrations and respective sql files
โโโ public # Public assets folder
โโโ src
โ โโโ layouts # Layouts components
โ โโโ pages # Next JS Pages
โ โโโ pages.test # Next JS Pages tests (this avoid test to treated as a Next.js pages)
โ โโโ styles # Styles folder
โ โโโ templates # Default template
โ โโโ utils # Utility functions
โโโ tailwind.config.js # Tailwind CSS configuration
โโโ tsconfig.json # TypeScript configuration
You can easily configure Next js Boilerplate. Please change the following file:
public/apple-touch-icon.png
,public/favicon.ico
,public/favicon-16x16.png
andpublic/favicon-32x32.png
: your website favicon, you can generate from https://favicon.io/favicon-converter/src/styles/global.css
: your CSS file using Tailwind CSSsrc/utils/AppConfig.ts
: configuration filesrc/templates/Main.tsx
: default theme
You can see the results locally in production mode with:
$ yarn build
$ yarn start
The generated HTML and CSS files are minified (built-in feature from Next js). It will also removed unused CSS from Tailwind CSS.
You can create an optimized production build with:
yarn build-prod
Now, your blog is ready to be deployed. All generated files are located at out
folder, which you can deploy with any hosting service.
All tests are colocated with the source code inside the same directory. So, it makes it easier to find them. Unfortunately, it is not possible with the pages
folder which is used by Next.js for routing. So, what is why we have a pages.test
folder to write tests from files located in pages
folder.