Begin I want to record how to setting up a NextJS project with TypeScript.
Let’s go Create a NextJS Project 1 yarn create next-app --typescript [your project path]
Yes, I used yarn. I prefer yarn to npm.
This article is very subjective. If you do not feel comfortable reading it. Please close it as soon as possible. If you think my article can help you, you can subscribe to this site by using RSS .
Add an EditorConfig File Add .editorconfig
file to root directory.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # EditorConfig is awesome: https://EditorConfig.org # top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file [*] end_of_line = lf insert_final_newline = true # Matches multiple files with brace expansion notation # Set default charset [*.{js,tsx}] charset = utf-8 indent_style = space indent_size = 2 # Matches the exact files either package.json or .travis.yml [{package.json,.travis.yml}] indent_style = space indent_size = 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 npx install gst . . . Need to install the following packages: gts Ok to proceed? (y) y . . . Already have devDependency for typescript: -4.3.2 +^4.0.3 ? Overwrite No . . . ./tsconfig.json already exists ? Overwrite No
and need add a line code to tsconfig.json
1 2 3 4 5 { ... "extends" : "./node_modules/gts/tsconfig-google.json" , ... }
and remove src/index.ts
Add VSCode setting.json I used VSCode Create new file .vscode/settings.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 { "editor.renderWhitespace": "all", "editor.defaultFormatter": "esbenp.prettier-vscode", "[javascript]": { "editor.formatOnSave": true }, "[javascriptrect]": { "editor.formatOnSave": true }, "[json]": { "editor.formatOnSave": true }, "[typescript]": { "editor.formatOnSave": true }, "[typescriptreact]": { "editor.formatOnSave": true } }
Add TailWindCSS I love tailwindcss. It is very useful. So I will add it on project.
Install Tailwind via 1 yarn add -D tailwindcss@latest postcss@latest autoprefixer@latest
Create your configuration files 1 2 3 4 5 6 7 8 9 10 11 12 module .exports = { purge : ['./pages/**/*.{js,ts,jsx,tsx}' , './components/**/*.{js,ts,jsx,tsx}' ], darkMode : false , theme : { extend : {}, }, variants : { extend : {}, }, plugins : [], }
Include Tailwind in your CSS 1 2 3 4 @tailwind base;@tailwind components;@tailwind utilities;
Now you can begin your work!
Reference NextJS Document What is EditorConfig? Google TypeScript Style Getting started with Tailwind CSS
Photo by Ferenc Almasi on Unsplash