This repository was archived by the owner on Mar 30, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork7
Project Setup with NextJs, Typescript, EmotionJs
NotificationsYou must be signed in to change notification settings
Project-Setup/Nextjs_Ts_Eslint
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- NextJs v10.0.5
- react v17.0.1
- Typescript v4.1.3
- @emotion/react v11.1.4
- setup node env
nvm use|| npm install - remove unwanted files in
public/,src/ - add
.envand other .env files - preview dev progress on
http://localhost:3000/npm run dev
- readSetup for notes
- install nvm in the os
nvm install nodegit init
- add
.gitignore node -v> .nvmrcnpm init -y
npm i -S next react react-dom
- add a script to your package.json like this:
{"scripts": {"dev":"next dev","build":"next build","start":"next start" }}
npm i -D typescript @types/react @types/node
- create
tsconfig.json{"compilerOptions": {"target":"esnext","lib": ["dom","dom.iterable","esnext"],"allowJs":true,"allowSyntheticDefaultImports":true,"alwaysStrict":true,"skipLibCheck":true,"strict":false,"forceConsistentCasingInFileNames":true,"noEmit":true,"noFallthroughCasesInSwitch":true,"noUnusedLocals":true,"noUnusedParameters":true,"esModuleInterop":true,"module":"esnext","moduleResolution":"node","resolveJsonModule":true,"isolatedModules":true,"jsx":"preserve","baseUrl":"./src" },"include": ["next-env.d.ts","**/*.ts","**/*.tsx"],"exclude": ["node_modules","next.config.js"]}
- create
src/pagesfolder (orpages) - create
pages.tsxundersrc/pages/(i.e.src/pages/index.tsxfor/route)
npm i -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react eslint-import-resolver-typescriptnpm i -D eslint-config-airbnb eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react-hooksnpm i -D prettier eslint-config-prettier eslint-plugin-prettier
- create
.eslintrc.jsmodule.exports={env:{browser:true,node:true,es2020:true,jest:true,},parser:'@typescript-eslint/parser',// Specifies the ESLint parserparserOptions:{ecmaVersion:2020,sourceType:'module',ecmaFeatures:{jsx:true,},},plugins:['@typescript-eslint','react','react-hooks','prettier'],extends:['airbnb','plugin:@typescript-eslint/recommended','plugin:react/recommended','plugin:import/errors','plugin:import/warnings','plugin:import/typescript','prettier','prettier/@typescript-eslint','prettier/react','plugin:prettier/recommended',// Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.],rules:{'@typescript-eslint/no-unused-vars':['error',{vars:'all',args:'after-used',ignoreRestSiblings:false,},],'@typescript-eslint/no-explicit-any':0,'@typescript-eslint/explicit-function-return-type':0,'@typescript-eslint/no-namespace':0,'@typescript-eslint/explicit-module-boundary-types':0,'import/extensions':[1,{extensions:['.js','.jsx','.ts','.tsx']},],'import/no-extraneous-dependencies':['error',{devDependencies:true,},],'react/jsx-filename-extension':[1,{extensions:['.js','.jsx','.ts','.tsx']},],'react/react-in-jsx-scope':0,'react/jsx-first-prop-new-line':0,'react/prop-types':0,'react/jsx-props-no-spreading':[2,{custom:'ignore'}],'jsx-a11y/anchor-is-valid':['error',{components:['Link'],specialLink:['hrefLeft','hrefRight'],aspects:['invalidHref','preferButton'],},],'prettier/prettier':2,'react-hooks/rules-of-hooks':2,'react-hooks/exhaustive-deps':2,'no-bitwise':2,},settings:{'import/resolver':{node:{extensions:['.js','.jsx','.ts','.tsx'],},typescript:{},},react:{version:'detect',// Tells eslint-plugin-react to automatically detect the version of React to use},},};
- create
.prettierrc.jsmodule.exports={semi:true,trailingComma:'es5',singleQuote:true,printWidth:80,tabWidth:2,};
npm i -D jest babel-jest @types/jest @next/env
add scripts in
package.json"scripts": {"test":"jest","test:watch":"jest --watch","test:coverage":"jest --coverage"},
create
jest.config.jsmodule.exports={moduleFileExtensions:['ts','tsx','js'],testRegex:'(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|js?|tsx?|ts?)$',globals:{NODE_ENV:'test',},snapshotSerializers:['enzyme-to-json/serializer'],transform:{'^.+\\.(j|t)sx?$':'babel-jest',},coveragePathIgnorePatterns:['/node_modules/','jest.setup.js','<rootDir>/configs/','jest.config.js','.json','.snap',],setupFiles:['<rootDir>/jest/jest.setup.js'],coverageReporters:['json','lcov','text','text-summary'],moduleNameMapper:{'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':'<rootDir>/__mocks__/mocks.js','\\.(css|less|scss)$':'<rootDir>/__mocks__/mocks.js',},moduleDirectories:['node_modules','src'],};
create
babel.config.jsmodule.exports={presets:['next/babel'],};
create
jest/jest.setup.jsimport{join}from'path';import{loadEnvConfig}from'@next/env';// to load '.env' files in testloadEnvConfig(join(__dirname,'../'));
change
envin.eslintrc.jsenv:{browser:true,node:true,jest:true},
npm i -S @emotion/reactnpm i -D @emotion/babel-plugin @emotion/eslint-plugin @emotion/jest
change
babel.config.jsmodule.exports={presets:[['next/babel',{'preset-react':{runtime:'automatic',importSource:'@emotion/react',},},],],plugins:['@emotion/babel-plugin'],};
add rules and plugins to
.eslintrc.jsmodule.exports={// ...rules:{// ...'@emotion/no-vanilla':'error','@emotion/import-from-emotion':'error','@emotion/styled-import':'error',},// ...plugins:['@emotion',// ...],// ...};
add
jest/jest.setupAfterEnv.jsimport{matchers}from'@emotion/jest';expect.extend(matchers);
add serializers and setup files to
jest/jest.config.js// ...snapshotSerializers:['@emotion/jest/serializer'],// ...setupFilesAfterEnv:['<rootDir>/jest.setupAfterEnv.js'],// ...
add to
tsconfig.json{"compilerOptions": {"jsxImportSource":"@emotion/react" }}
(deploy to /docs intead of using gh-pages branch; replace {folder} with the project name in github repo)
- add
.env.productionNEXT_PUBLIC_LINK_PREFIX=/{folder} - create
LINK_PREFIXinnext.config.jsconstLINK_PREFIX=process.env.NEXT_PUBLIC_LINK_PREFIX||'';module.exports=()=>({basePath:LINK_PREFIX,});
- change
scriptsinpackage.json{"scripts": {"export":"NODE_ENV=production npm run build && next export -o docs && touch docs/.nojekyll" }}
About
Project Setup with NextJs, Typescript, EmotionJs
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.