Git Product home page Git Product logo

nextjs-boilerplate's Introduction

NextJs Boilerplate

The purpose of this repo is to accelerate startup time when creating a new NextJs app.

Contents

Getting Started

First, install npm packages

npm install

Then, run the development server:

npm run dev

Open http://localhost:3000 with your browser to start.

Directory Structure

๐Ÿ“ฆ src
โ”ฃ ๐Ÿ“‚ __tests__               # tests for pages
โ”ƒ โ”— ๐Ÿ“œ index.test.tsx
โ”ฃ ๐Ÿ“‚ components              # components used within the app
โ”ƒ โ”— ๐Ÿ“œ Posts.tsx
โ”ฃ ๐Ÿ“‚ context                 # application context providers 
โ”ƒ โ”— ๐Ÿ“œ AppState.tsx
โ”ฃ ๐Ÿ“‚ core                    # non-feature related core services
โ”ƒ โ”ฃ ๐Ÿ“‚ mocks
โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“‚ seed
โ”ƒ โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œ seedPosts.js
โ”ƒ โ”ƒ โ”ƒ โ”— ๐Ÿ“œ seedStyleMedia.js
โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œ mswHandlers.js
โ”ƒ โ”ƒ โ”— ๐Ÿ“œ mswServer.js
โ”ƒ โ”— ๐Ÿ“œ test.utils.tsx
โ”ฃ ๐Ÿ“‚ hooks                   # hooks used within the app
โ”ƒ โ”ฃ ๐Ÿ“‚ __tests__
โ”ƒ โ”ƒ โ”— ๐Ÿ“œ usePosts.test.ts
โ”ƒ โ”— ๐Ÿ“œ usePosts.ts
โ”ฃ ๐Ÿ“‚ pages                   # pages directory - drives navigation
โ”ƒ โ”ฃ ๐Ÿ“‚ api
โ”ƒ โ”ƒ โ”— ๐Ÿ“œ posts.ts
โ”ƒ โ”ฃ ๐Ÿ“œ _app.tsx
โ”ƒ โ”— ๐Ÿ“œ index.tsx
โ”— ๐Ÿ“‚ services                # feature-related services
โ”ƒ โ”ฃ ๐Ÿ“‚ __tests__
โ”ƒ โ”ƒ โ”— ๐Ÿ“œ postsService.test.ts
โ”ƒ โ”— ๐Ÿ“œ postsService.ts

Features

The setup and configuration includes a number of opinionated best-practices in attempt to keep the code clean, safe, and free of bugs.

Code is formatted and linted with each save, if configured, or at least before each commit with the help of husky.

Tests are configured for both unit and integration tests. Unit tests are performed with jest where msw helps avoid mocking http requests, both server and client, which allows for easier integration tests.

Libraries

Application Description
react react framework
nextJs nextjs framework
typescript Enabling typescript
react-query Data-fetching library
Static-code Analysis Description
eslint Helps identify code issues
prettier code formatting tool
Testing Description
jest-junit Testing Library
msw Used to intercept and mock http requests
testing-library-react Helper for UI component tests
testing-library-react-hooks Helper for react-hook tests
jest-html-reporters Test reporter for visualizing tests
Git Hooks Description
husky Creates sharable git-commit hooks
lint-staged Ensure code is linted before committing to branch
validate-branch-name Ensures a branch is created before committing to master/main

Scripts

npm run test    # runs all tests, creating test report
npm run test:open    # opens the test report
npm run test:cover    # runs all tests, creating coverage report
npm run test:cover:open    # opens the coverage report
npm run lint    # runs lint check, produces report
npm run lint:fix    # runs lint and fixes, produces report

Utility scripts

npm run prepare   # installs husky hook - this lints the app before each commit
npm run format   # run code format check
npm run format:fix   # run fix code formatting
npm run pre-commit   # this is ran prior to a git commit - runs lint and checks branch name

IDE-configuration

VS Code

The .vscode directory is checked into this repo and serves to share common settings and defaults.

Recommended Extensions are configured, be sure to install.

Setting Description
eslint.validate Validate and fixes eslint errors. This also fixes prettier issues
typescript.suggest.paths Turned off to enable correct usage within auto-rename-tag
Extension Description
code-spell-checker checks spelling errors withing the code
vscode-icons Directory icons
vscode-jest Helps renaming tags
auto-rename-tag Helps renaming tags
vscode-eslint Integrate with lint rules

Snippets

// entering: desc
describe('', () => {
  
});
// entering: it
it('should ', () => {
  // arrange
  // act

  // assert
});
// entering: ita
it('should ', async () => {
  // arrange
  // act
  
  // assert
});
// entering: func
export default function () {

}
// entering: hook
export default function use() {

}

Webstorm

The .idea directory is checked into this repo and serves to share common run configurations

Setting Description
All Tests Execute and watch all tests
Dev Run application

Committing Changes

Husky makes git hooks sharable within a project while also ensuring code conventions are enforced. The hook is installed during npm install and should require no further setup.

Husky pre-commit is configured to run the npm task pre-commit which does the following:

  • Avoid commits to master/main
  • Format staged code
  • Lint staged code

Should the need arise to ignore the hook, manually commit using --no-verify

# Example
git commit -m "commit message" --no-verify

nextjs-boilerplate's People

Contributors

freakinward avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.