Netlify CMS & Next.js Series - Next.js Setup

Senior Full-Stack Developer with over 20 years of experience building web applications for startups, government, and higher education.
Search for a command to run...

Senior Full-Stack Developer with over 20 years of experience building web applications for startups, government, and higher education.
No comments yet. Be the first to comment.
This will be a series of posts were I setup a simple brochure site in Next.js driven by the Netlify CMS.
We're going to be using markdown to create our pages so lets add a markdown loader: yarn add frontmatter-markdown-loader -D Add markdown content Create a content folder and some sample content: filename: content/index.md --- header: title: Softwa...
Writing this up so I have somewhere to quickly grab basic Jest setup. This information is copied from the Jest Documentation Site compressed into just the parts I'm interested in. Create folders mkdir -p <project>/src cd <project> Install and init n...

In this blog post, we'll explore the process of setting up and configuring a Postgres database using Docker and seeding it with test data. This approach can be used for a variety of apps and can be easily adapted for your own needs. We'll cover all t...

Continuing from last time, we will explore the concepts behind Create and Update functionality and provide a step-by-step guide on how to implement it in your SvelteKit application. Let's get started! Server & Client Code In SvelteKit, the server-sid...

Introduction In this post, I will explore how to create a REST API using Spring Boot and Kotlin. We will dive into the fundamentals of Spring Boot and Kotlin, explain how to set up the project, and guide you through the process of building the API st...

Introduction Welcome to the latest post in my series of Koan Battles using Kotlin and TypeScript. In this series, we'll complete a Koan in both languages and then discuss the differences between the two solutions. My goal is to help you gain a deeper...

Well setup Next.js using Typescript , ESLint , Prettier and Tailwind CSS.
Run the following commands to create a blank next.js project and test its working:
yarn create next-app client-cms
cd client-cms
yarn dev
You should see something like:

Add TypeScript using the command:
yarn add typescript @types/react @types/node -D
Rename the .js files to .tsx:
pages/_app.js -> pages/_app.tsx
pages/index.js -> pages/index.tsx
Run yarn dev again and next.js should detect the TypeScript files and generate a tsconfig.json file.
yarn dev
We detected TypeScript in your project and created a tsconfig.json file for you.
Install ESLint & Prettier using the command:
yarn add @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-react prettier eslint -D
Create a ESLint config file in the root of the project:
filename: .eslintrc.js
module.exports = {
env: {
browser: true,
node: true,
es2020: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
plugins: ["@typescript-eslint", "react", "prettier"],
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"prettier",
"prettier/@typescript-eslint",
"prettier/react",
],
rules: {
"react/jsx-filename-extension": [1, { extensions: [".ts", ".tsx"] }],
"import/extensions": 0,
"react/prop-types": 0,
"react/jsx-props-no-spreading": ["error", { custom: "ignore" }],
"prettier/prettier": "error",
},
settings: {
"import/resolver": {
node: {
paths: ["~"],
},
},
},
};
Add and setup Tailwind CSS using the following commands:
yarn add tailwindcss -D
npx tailwind init
This creates a tailwind.config.js file. Update the tailwind config file with purge settings:
filename: tailwind.config.js
module.exports = {
purge: [
'./components/**/*.{js,ts,jsx,tsx}',
'./pages/**/*.{js,ts,jsx,tsx}',
'./content/**/*.md'
],
theme: {
extend: {},
},
variants: {},
plugins: [],
future: {
removeDeprecatedGapUtilities: true,
purgeLayersByDefault: true,
}
}
Add a PostCSS config file, create the following file in the root of the project:
filename: postcss.config.js
module.exports = {
plugins: ['tailwindcss', 'postcss-preset-env'],
future: {
removeDeprecatedGapUtilities: true,
purgeLayersByDefault: true,
},
}
Add the PostCSS Preset Env module which converts modern CSS to wider browser compatibility format:
yarn add postcss-preset-env -D
Create a tailwind.css file to import Tailwind CSS:
filename: styles/tailwind.css
@tailwind base;
@tailwind components;
@tailwind utilities;
Update the next _app.tsx file to import tailwind.css:
filename: pages/_app.tsx
import '../styles/tailwind.css'
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp
I've removed the import of the global.css file as we'll be deleting that file during the clean up step below.
Remove the Home.module.css import from index.tsx and any references to the styles and images:
import Head from "next/head";
export default function Index() {
return (
<div className="p-4">
<Head>
<title>devfair client cms</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<h1 className="text-6xl">
Welcome to <a href="https://devfair.com">devfair client cms!</a>
</h1>
<p className="mt-0 mb-4 text-gray-600">
Get started by editing <code>pages/index.tsx</code>
</p>
</main>
</div>
);
}
Delete the unused files:
styles/globals.css
styles/Home.module.css
public/vercel.svg
pages/api/hello.js
When you run yarn dev you should now have a working next.js site with typescript, tailwind.css setup:
