nextjs-web-app/ALTERNATIVES.md

4.5 KiB

Alternative Approaches to Template Management

Current Approach: Simple Copy

cp -r ~/Projects/nextjs-starter ~/Projects/my-project
cd ~/Projects/my-project
./setup.sh

Pros:

  • Simple and fast
  • No external dependencies
  • Works offline
  • Easy to understand

Cons:

  • Feels "low-tech"
  • Manual process
  • No built-in versioning

Better Alternatives

Setup once:

cd ~/Projects/nextjs-starter
gh repo create nextjs-starter --public --source=. --remote=origin
git push -u origin main
# Enable "Template repository" in GitHub Settings

Usage:

npx create-next-app my-project --example https://github.com/yourusername/nextjs-starter
cd my-project
npm run dev

Pros:

  • Official Next.js tool
  • Industry standard
  • Automatic npm install
  • Clean (no git history)
  • Shareable with team

Cons:

  • Requires GitHub
  • Requires internet

2. degit (Fast, No Git History)

Usage:

npx degit yourusername/nextjs-starter my-project
cd my-project
npm install

Pros:

  • Very fast
  • No git history
  • Popular in JS community
  • Works with GitHub/GitLab/Bitbucket

Cons:

  • Requires GitHub
  • Requires internet

3. npm init / create Package (Most Professional)

Create a package like create-my-app:

Setup:

# Create a new package
mkdir create-my-nextjs-app
cd create-my-nextjs-app
npm init -y

# Add template files
mkdir template
cp -r ~/Projects/nextjs-starter/* template/

# Create index.js that copies template
# Publish to npm
npm publish

Usage:

npm create my-nextjs-app my-project
# or
npx create-my-nextjs-app my-project

Pros:

  • Most professional
  • Like create-react-app, create-next-app
  • Can add interactive prompts
  • Versioned via npm
  • Can be private or public

Cons:

  • More setup work
  • Requires npm registry
  • Overkill for personal use

4. Yeoman Generator (Old School but Powerful)

npm install -g yo generator-generator
yo generator

Pros:

  • Very powerful
  • Interactive prompts
  • Conditional logic
  • File templating

Cons:

  • Old technology (2012)
  • Feels outdated
  • Heavy dependency

5. Plop.js (Modern Alternative to Yeoman)

npm install --save-dev plop

Pros:

  • Modern
  • Micro-generator
  • Good for components
  • Used by many teams

Cons:

  • More for components than full projects
  • Requires setup

Recommendation

For Personal Use (Current)

Stick with simple copy - it works, it's fast, and you don't need complexity.

For Team/Public Use

Use GitHub Template + create-next-app:

  1. Push to GitHub once
  2. Enable template repository
  3. Use: npx create-next-app my-app --example https://github.com/you/nextjs-starter

This is the industry standard and what most developers expect.

For Professional Product

Create npm package (create-my-app):

  • Most professional
  • Versioned
  • Can be private
  • Like create-react-app

About setup.sh

The setup.sh script follows standard bash practices:

  • Shebang (#!/bin/bash)
  • Error handling (set -e)
  • Input validation
  • User feedback
  • Self-deletes after use (clean)
  • Cross-platform (macOS/Linux)

This is similar to:

  • Ruby on Rails generators
  • Laravel artisan commands
  • Django management commands

It's not "off the cuff" - it's a standard pattern for setup scripts.


Comparison to Django Cookiecutter

Feature Cookiecutter GitHub Template npm create
Templating Jinja2 None Custom
Prompts Yes No Yes (if custom)
Ecosystem Python Git JavaScript
Speed Medium Fast Fast
Complexity Medium Low High
Best For Python projects Any project JS projects

My Recommendation for You

Phase 1 (Now): Keep the simple copy approach

  • It works
  • It's fast
  • No dependencies
  • Easy to maintain

Phase 2 (When sharing): Push to GitHub as template

  • One-time setup
  • Use create-next-app --example
  • Industry standard
  • Easy for others

Phase 3 (If building product): Create npm package

  • Professional
  • Versioned
  • Shareable
  • Like create-react-app

Bottom line: The current approach is fine for personal use. It's not "low-tech" - it's pragmatic. When you need to share it, upgrade to GitHub template. 🎯