This is a Vanilla JS Next.js project bootstrapped with create-next-app, Storybook and TailwindCSS.

How To: Setting Up This Repo

  1. Create the next app and use npm as the package manager: npx create-next-app@latest next-storybook-example --use-npm
  2. Tooled next.config.js to support Sass
  3. Installed Tailwind: npm install -D tailwindcss postcss autoprefixer
  4. Run tailwind boot: npx tailwindcss init -p, which creates tailwind.config.js and postcss.config.js
  5. Create components/ folder
  6. Add tailwind base classes to globals.classes
  7. Install Storybook: npx init sb, creates .storybook folder
  8. Customize Postcss config for Next

Gotchas

If you are doing server side rendering or client side fetches, any API url environment variable must be prepended with NEXT_PUBLIC_ or it will not interpolate successfully. See Environment Variables doc

Resources

Tailwind Playground

Getting Started

Running the development server:

npm run dev

Running storybook npm run storybook

Build Storybook

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying pages/index.js. The page auto-updates as you edit the file.

API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.js.

The pages/api directory is mapped to /api/*. Files in this directory are treated as API routes instead of React pages.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Folder Structure

.//ROOT LEVEL
.gitignore
├── README.md
├── components         // stores all components
├── hooks              // context and hook functions
├── next.config.js     // takes next plugins, wraps around webpack, configures your build and compilation
├── node_modules
├── package-lock.json
├── package.json
├── pages               // page templates
  ├── api               // api routes and handler functions, much like next's own express 
├── public              // static assets go here
├── styles
├── tailwind.config.js  // configure tailwind in terms of theme and token values
├── postcss.config.js   // for tree-shaking and minimizing CSS (dead-code elimination)

Add a lib/ or util/ folder if you would like!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.