### Run Development Server Commands Source: https://github.com/hohoemi-rabo/post-craft/blob/main/README.md Commands to start the development server for the Next.js project using different package managers like npm, yarn, pnpm, and bun. These commands initiate the local development environment. ```bash npm run dev yarn dev pnpm dev bun dev ``` -------------------------------- ### Start Development Server with Package Managers Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt These commands start the local development environment for the Next.js application with hot reload and Turbopack bundler. Choose the command that corresponds to your preferred package manager. ```bash # Start development server on http://localhost:3000 npm run dev # Alternative package managers yarn dev pnpm dev bun dev ``` -------------------------------- ### Build Production Bundle and Start Production Server Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt These commands compile and optimize the Next.js application for deployment. The `build` command creates an optimized production bundle, and the `start` command launches the production server. ```bash # Build optimized production bundle npm run build # Start production server after build npm run start # Expected output structure in .next/ directory: # - Static pages pre-rendered # - Optimized JavaScript bundles # - Image optimization cache ``` -------------------------------- ### Create Reusable React Components Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt Building custom React components in the `src/components` directory with proper TypeScript typing and Tailwind styling. This example demonstrates creating a reusable Button component with different variants and applying it in a page. ```typescript // src/components/Button.tsx interface ButtonProps { children: React.ReactNode; onClick?: () => void; variant?: 'primary' | 'secondary'; } export default function Button({ children, onClick, variant = 'primary' }: ButtonProps) { const baseStyles = "rounded-full font-medium px-4 py-2 transition-colors"; const variantStyles = { primary: "bg-foreground text-background hover:bg-[#383838]", secondary: "border border-foreground hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a]" }; return ( ); } // Usage in page import Button from '@/components/Button'; export default function Page() { return ; } ``` -------------------------------- ### Create Next.js App Router Pages Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt Examples of creating new routes by adding files in the `src/app` directory, following Next.js App Router conventions. This includes creating static pages, dynamic routes, and API endpoints. ```typescript // src/app/about/page.tsx export default function About() { return (

About Page

This is a new route at /about

); } // src/app/blog/[slug]/page.tsx - Dynamic route export default function BlogPost({ params }: { params: { slug: string } }) { return (

Blog Post: {params.slug}

); } // src/app/api/hello/route.ts - API endpoint export async function GET() { return Response.json({ message: 'Hello from API' }); } ``` -------------------------------- ### Configure Tailwind CSS with Custom Theme Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt Custom theme configuration extending default Tailwind with CSS variables for color scheme and font families. This setup allows for dynamic theming based on CSS variables, enhancing flexibility for color palettes and font choices. It targets specific directories for content scanning. ```typescript import type { Config } from "tailwindcss"; const config: Config = { content: [ "./src/app/**/*.{js,ts,jsx,tsx,mdx}", "./src/components/**/*.{js,ts,jsx,tsx,mdx}", "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", ], theme: { extend: { colors: { background: "var(--background)", foreground: "var(--foreground)", }, fontFamily: { sans: [ "var(--font-geist-sans)", "ui-sans-serif", "system-ui", "-apple-system", "sans-serif", ], mono: [ "var(--font-geist-mono)", "ui-monospace", "SFMono-Regular", "Menlo", "Monaco", "Consolas", '"Liberation Mono"', '"Courier New"', "monospace", ], }, }, }, plugins: [], }; export default config; ``` -------------------------------- ### Configure Next.js Application Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt Basic Next.js configuration file, ready for custom webpack, redirects, headers, and environment settings. This serves as a template for customizing Next.js behavior, including image optimization, environment variables, and server-side configurations. ```typescript import type { NextConfig } from "next"; const nextConfig: NextConfig = { // Add custom configuration: // - images: { domains: ['example.com'] } // - env: { CUSTOM_KEY: 'value' } // - redirects: async () => [{ source: '/old', destination: '/new', permanent: true }] // - webpack: (config) => { return config; } }; export default nextConfig; ``` -------------------------------- ### Global Styles with Theming and Dark Mode Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt Global CSS configuration using Tailwind directives and CSS custom properties for theming with automatic dark mode support. This sets up base styles for the body, including background and foreground colors, and font family, adapting to the user's preferred color scheme. ```css @tailwind base; @tailwind components; @tailwind utilities; :root { --background: #ffffff; --foreground: #171717; } @media (prefers-color-scheme: dark) { :root { --background: #0a0a0a; --foreground: #ededed; } } body { background: var(--background); color: var(--foreground); font-family: var(--font-geist-sans), ui-sans-serif, system-ui, -apple-system, sans-serif; } ``` -------------------------------- ### Configure TypeScript Compiler Options Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt TypeScript compiler options configured for Next.js, including strict mode, path aliases, and module resolution. This JSON file defines how the TypeScript compiler should process the project's code, ensuring type safety and efficient module handling. ```json { "compilerOptions": { "target": "ES2017", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "strict": true, "noEmit": true, "esModuleInterop": true, "module": "esnext", "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", "incremental": true, "plugins": [ { "name": "next" } ], "paths": { "@/*": ["./src/*"] } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": ["node_modules"] } ``` -------------------------------- ### Run ESLint for Code Quality Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt Command to run ESLint with Next.js specific rules to maintain code quality and catch common errors. ESLint checks for React hooks usage, Next.js best practices, TypeScript type errors, unused variables, and accessibility warnings. ```bash # Run linter on all TypeScript/JavaScript files npm run lint # Expected checks: # - React hooks usage rules # - Next.js best practices # - TypeScript type errors # - Unused variables and imports # - Accessibility warnings (a11y) ``` -------------------------------- ### Home Page Component in Next.js with TypeScript Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt This TypeScript code defines the home page component for the Next.js application. It imports the Image component from Next.js and defines a functional component that renders a responsive layout with an image and text. ```typescript import Image from "next/image"; export default function Home() { return (
Next.js logo
  1. Get started by editing{" "} src/app/page.tsx .
  2. Save and see your changes instantly.
Vercel logomark Deploy now
); } ``` -------------------------------- ### Root Layout Component in Next.js with TypeScript Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt This TypeScript code defines the root layout component for the Next.js application. It imports necessary modules, defines font configurations, sets metadata, and renders the basic HTML structure with font styles. ```typescript import type { Metadata } from "next"; import { Geist, Geist_Mono } from "next/font/google"; import "./globals.css"; const geistSans = Geist({ variable: "--font-geist-sans", subsets: ["latin"], }); const geistMono = Geist_Mono({ variable: "--font-geist-mono", subsets: ["latin"], }); export const metadata: Metadata = { title: "Create Next App", description: "Generated by create next app", }; export default function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { return ( {children} ); } ``` -------------------------------- ### Accessing Environment Variables in Next.js Source: https://context7.com/hohoemi-rabo/post-craft/llms.txt Demonstrates how to access environment variables within Next.js components and server-side code. Publicly exposed variables (NEXT_PUBLIC_*) are accessible in the browser, while all variables are available on the server. ```javascript const apiUrl = process.env.NEXT_PUBLIC_API_URL; const dbUrl = process.env.DATABASE_URL; const secret = process.env.SECRET_KEY; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.