chakraui-react-next.js-typescript-eslint-jest-starter
chakraui-react-next.js-typescript-eslint-jest-starter copied to clipboard
Starter template for building a project using React, Typescript, Next.js, Jest, ChakraUI and ESLint.
chakraui-react-next.js-typescript-eslint-jest-starter
Starter template for building a project using React, Typescript, Next.js, Jest, ChakraUI and ESLint.
Setup Instructions
- Clone or download the project.
cdin the project directory.- If you cloned the project, make sure you remove the remote reference to this project by running
git remote rm origin. - Copy
.env.exampleto.envas that file is used to load up all your environment variables. - Run
yarn installornpm installto install all dependencies.
Commands
-
yarn dev: To start a local development server. -
yarn test: To run the entire unit test suite usingjest. -
yarn test:ci: To run tests on CI. -
yarn lint: To run the ESLint based linter to find out the issues in the project. -
yarn format: To autoformat all the issues. -
yarn export: Run this after runningyarn analyzeto export a build copy. -
yarn production: To export a production build. Useyarn startto serve that. -
yarn upgrade --latest: To upgrade all packages to their latest versions (could include breaking changes).
Code Structure
All source code is located in the src/ directory:
-
All Next.js entrypoints are housed in the
src/pagesdirectory as a default.- Currently has
_app.tsxwhich bootstraps ChakraUI within this project. - There's also a sample
index.tsx.
NOTE: Feel free to move
pagesoutside ofsrc/if that's what you prefer. You'll just need to restart your local development server and everything should continue working as normal. - Currently has
-
src/componentsare all stateless reusable components.- Includes a dummy
MainHeadingcomponent with a JEST test as a sample. Feel free to delete this.
- Includes a dummy
-
src/stylesfolder is there just to house any styling.- It currently contains the ChakraUI theme ready for you to extend. This file has already been imported in
_app.tsxand is already supplied as a prop toChakraProvider.
- It currently contains the ChakraUI theme ready for you to extend. This file has already been imported in
-
All env variables are available in
.envfiles (.envfile isn't committed). Whenever you update.env, please update.env.exampleand.env.testandnext.config.jsto proxy all environment variables properly.- You can access these variables in the app source code anywhere using
process.env.<VAR_NAME>.
- You can access these variables in the app source code anywhere using
If you feel like changing the directory structure, please change the appropriate settings in the following files:
.swcrcjest.config.jstsconfig.json- The
lintand theformatscripts inpackage.json
Note
-
This project removes the
x-powered-byresponse header vianext.config.jsby marking thepoweredByHeaderproperty asfalse. -
If you wish to use Babel instead of SWC (introduced with the Next.js v12 upgrade), please remove the
.swcrcfile and add a.babelrcfile at the root with the following:
{
"presets": [
"next/babel"
],
"plugins": [
[
"module-resolver",
{
"root": [
"./"
],
"alias": {
"@src": "./src"
},
"extensions": [
".js",
".jsx",
".ts",
".tsx"
]
}
]
]
}
Then, open ./jest.config.js and find the globals config. Add babelConfig to it, like so:
{
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.jest.json',
babelConfig: true,
diagnostics: false,
},
},
}
Also, run yarn add -D @babel/core babel-plugin-module-resolver eslint-import-resolver-babel-module to install Babel's dependencies.