arrow-left
Only this pageAll pages
gitbookPowered by GitBook
1 of 9

Next.js WebApp Starter documentation

Loading...

Loading...

Loading...

Development

Loading...

Page Components

Loading...

Misc

Loading...

Introduction

An up-to-date, reasonably opinionated starter template for Next.js web apps

hashtag
What is Next.js WebApp Starter?

Next.js WebApp Starterarrow-up-right is an up-to-date, reasonably opinionated Next.js starter template. It's bootstrapped with create-next-apparrow-up-right, complemented with some icing on top (the reasonably opinionated part).

Note: This is a community-created project and is not affiliated with Vercelarrow-up-right or Next.jsarrow-up-right.

circle-info

We only cover core Next.js features in our documentation when it's necessary to help explain a Next.js WebApp Starter feature. To learn more about Next.js itself check out .

hashtag
Features

Next.js WebApp Starter comes with the following features:

  • It's .

  • is added as a in the Next.js build chain.

  • sass library installed to enable Next.js' built-in Sass support.

We're currently in a 0.x iterative release cycle. Check out the version 1.0 roadmap .

hashtag
Project Goals

The overarching goal of this project is to provide a Next.js starter template that has the following attributes:

  • Is open-source.

  • Actively maintained, with all project dependencies kept up to date.

  • Integrates new core Next.js features as soon as possible after new Next.js versions are released, accompanied by appropriate documentation in this project's official documentation site and, where suitable, in the code.

hashtag
Who created it?

Next.js WebApp Starter is an open source project started and being maintained by , a full stack software developer from Barbados.

If you would like to donate to my development efforts on this project, you can do so . All sponsors will be recognized in the project README and here in the documentation.

hashtag
How can I contribute?

Development of this project is being done in the open on GitHub and contributions are welcomed. To learn more about how you can contribute, please read the project's and .

next.config.jsarrow-up-right file ready for you to customize to enable the following Next.js 9.5+arrow-up-right core features:

  • Customizable Base Path

  • Rewrites, Redirects, and Headers

  • Optional Trailing Slash in URLs

  • Easy use of open source SVG icon packs via the @meronex/iconsarrow-up-right package.

  • Internationalization support via integration of the i18nextarrow-up-right and react-i18nextarrow-up-right internationalization frameworks.

  • Easy SEO management via the Next SEOarrow-up-right package.

  • PWA-enabled via next-pwaarrow-up-right

  • More to come...

  • Encourages community discussion around any and all features added that fall outside of core Next.js features, while staying aligned with the sub-goals of ensuring that each of these features:

    • is considered useful by the community

    • is implemented in a performant and secure manner

  • As much as possible, developer experience should be impacted only positively, not negatively.

  • Does not aim to be everything for everyone but instead aims to provide an out-of-the-box feature set that benefits the Next.js community.

  • their official documentationarrow-up-right
    configured as a Next.js TypeScript application
    Tailwind CSSarrow-up-right
    PostCSS pluginarrow-up-right
    herearrow-up-right
    Owan Huntearrow-up-right
    herearrow-up-right
    Code of Conductarrow-up-right
    Contributing Guidearrow-up-right

    Custom `App`

    src/pages/_app.tsx

    Next.js WebApp Starter implements the following custom App component:

    // import App from "next/app";
    import type { AppProps /*, AppContext */ } from "next/app";
    import Head from "next/head";
    import I18n from "i18n/create-provider";
    import App from "components/App";
    import "styles/index.css";
    
    function MyApp(props: AppProps) {
      return (
        <>
          <Head>
            <meta
              name="viewport"
              content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no, user-scalable=no, viewport-fit=cover"
            />
          </Head>
          <I18n
            requiredNS={props.pageProps.requiredNS}
            lng={props.pageProps.lng}
            lngDict={props.pageProps.lngDict}
          >
            <App {...props} />
          </I18n>
        </>
      );
    }
    
    // Only uncomment this method if you have blocking data requirements for
    // every single page in your application. This disables the ability to
    // perform automatic static optimization, causing every page in your app to
    // be server-side rendered.
    //
    // MyApp.getInitialProps = async (appContext: AppContext) => {
    //   // calls page's `getInitialProps` and fills `appProps.pageProps`
    //   const appProps = await App.getInitialProps(appContext);
    
    //   return { ...appProps }
    // }
    
    export default MyApp;

    Let's break down this file.

    Getting Started

    hashtag
    Option 1: Use create-next-app

    You can use create-next-apparrow-up-right to quickly create a new project with this Starter, by running the following command:

    Check out the development guides to familiarize yourself with the project's code structure.

    hashtag
    Option 2: GitHub's Use this template feature

    From this project's click the Use this template button to .

    There are two branches. The default branch, named release, contains the code for the latest stable release. The other branch, named canary, is the development branch and holds code for the next release. By default you will only get the release branch. If you want your repository to be created with the canary branch as well, make sure to select the Include all branches checkbox in the repository creation form.

    Depending on your workflow either clone, or fork and then clone your repository to your local environment and then do the following:

    1. Make sure you have (>= 10.21.0) installed.

    2. Install the dependencies:

    3. Run the Next.js development server:

      Open with your browser to run the web app. To specify a port other than 3000 use the

    hashtag
    Before you start coding

    We ship an opinionated feature set on top of the default app that create-next-app gives you. Check out the to familiarize yourself with the code structure of Next.js WebApp Starter.

    yarn create next-app [project-name] -e https://github.com/nextjs-starter/nextjs-webapp-starter
    # or
    npx create-next-app [project-name] -e https://github.com/nextjs-starter/nextjs-webapp-starter
    -p
    flag:
  • Go forth and code your awesome project! We recommend that you read the development guides.

  • GitHub repository homepagearrow-up-right
    create your own GitHub repository from itarrow-up-right
    Node.jsarrow-up-right
    http://localhost:3000arrow-up-right
    development guides
    cd path/to/app
    yarn  # or npm i
    yarn dev
    # or
    npm run dev
    yarn dev -p <some other port>   # e.g. yarn dev -p 3001

    TypeScript Integration

    Next.js WebApp Starter is developed as a TypeScript Next.js app. As such, there are a few things that are worth mentioning.

    Changelog

    hashtag
    v0.6.2 (2020-09-11)

    hashtag
    Changed

    • README: Re-ordered Getting Started options ()

    hashtag
    v0.6.1 (2020-09-11)

    hashtag
    Changed

    • Uninstalled github-buttons package ()

    • Updated i18next-http-backend and i18next-http-middleware dependencies ()

    hashtag
    v0.6.0 (2020-09-11)

    hashtag
    Added

    • PWA support via next-pwa ()

    hashtag
    Changed

    • Revamped index page layout ()

    • Updated README, changelog, Code of Conduct and contributing guide () () ()

    • Updated tests that were broken by new index page layout ()

    hashtag
    v0.5.0 (2020-09-06)

    hashtag
    Added

    • Jest and React Testing Library ()

    • Unit tests for the homepage (including tests for the header and footer components) ()

    • file to simply site-wide configuration of your Next.js project ()

    hashtag
    Changed

    • Refactor: Moved i18n and seo config files to config/ folder ()

    • README: Updated Features section ()

    hashtag
    v0.4.0 (2020-09-03)

    hashtag
    Added

    • Integrated Next SEO plugin library ()

    hashtag
    Fixed

    • Refactor: Replaced router.push calls in src/lib/utils.ts and src/pages/index.tsx with window.location.href calls to prevent React render error and content jump issue ()

    • Refactor: Check for presence of lng and translations static props before using useSSR

    hashtag
    Changed

    • Refactored code to use TS' type-only imports feature ()

    • Refactor: i18next and react-i18next are now integrated for i18n solution instead of rosetta ()

    • Refactor: Default

    hashtag
    v0.3.2 (2020-08-22)

    hashtag
    Added

    • Added removeDeprecatedGapUtilities flag to Tailwind config file to opt-in to Tailwind's upcoming breaking change ()

    hashtag
    Changed

    • Refactored custom TS type SupportedLocale to SupportedLanguage ()

    • Bumped NEXT_PUBLIC_APP_VERSION env var to 0.3.2 ()

    hashtag
    v0.3.1 (2020-08-21)

    A simple patch release to include the changes to the README and changelog that should have landed in the 0.3.0 release but didn't.

    hashtag
    v0.3.0 (2020-08-21)

    hashtag
    Added

    • file ready to be customized to enable the following core features: ()

      • Customizable Base Path

      • Rewrites, Redirects, and Headers

    hashtag
    Changed

    • Updated the Branch Organization section of the contributing guide ()

    • Updated Features section of the README to include next.config.js file addition ()

    • Bumped NEXT_PUBLIC_APP_VERSION

    hashtag
    v0.2.1 (2020-08-18)

    hashtag
    Fixed

    • Fixed index page component's responsive design ()

    • Index page now correctly queries and shows latest release version ()

    hashtag
    Changed

    • Removed version number from Docs badge in README ()

    • Added Code of Conduct ()

    • Added CONTRIBUTING file ()

    hashtag
    v0.2.0 (2020-08-16)

    hashtag
    Added

    • Converted starter template to TypeScript ()

    • Installed @meronex/icons package to allow SVG icons to be easily added.

    • Installed and configure Tailwind CSS framework.

    hashtag
    Changed

    • Added documentation section and badge to README ()

    • Added mention of Tailwind CSS and Sass feature additions to the README ()

    • Replaced default Next.js README with project-specific README ()

    hashtag
    v0.1.0 (2020-08-14)

    First release to match default web app created by create-next-app with the following differences:

    • Development packages , and added and configured to enforce local linting of commit messages that follow the .

    • Commands added to the package.json scripts property to bump package version, and commit and tag releases.

    Updated @types/node and tailwindcss dev dependencies ()
  • Opts-in to new by default ()

  • hook (
    )
  • Fixed React warning: Did not expect server HTML to contain a <div> in <div> () ()

  • lng
    to
    i18nConfig.defaultLng
    in
    getLocaleDataForStaticProps
    (
    )
  • Refactor: Updated getT function signature ()

  • Refactor: Removed babel-plugin-i18next-extract ()

  • Refactor: i18next debug mode now enabled for development and local build targets only ()

  • Build: Updated dependencies and devDependencies ()

  • README: Updated Features section to document that i18n integration is now done via instead of rosetta ()

  • README: Updated Features section to document Next SEO integration ()

  • README: Replaced Next.js version badge with dependencies badge ()

  • Updated all documentation site links to point to the new URL ()
  • Removed unused code from the Header component ()

  • Updated dev dependencies ()

  • Optional Trailing Slash in URLs

  • Demo deployment URL now included near the top of the README ()

  • Internationalization support via integration of the package ()

  • env var to
    0.3.0
    (
    )

    Improved README sections and content ()

  • Removed husky and @commitlint/* packages, git hook and configuration ()

  • Installed Sass library.

    Minimum required node version is set to
    10.21.0
    , instead of Next.js' 10.13.0.
  • EditorConfig file included.

  • Project is .

  • #55arrow-up-right
    #54arrow-up-right
    #54arrow-up-right
    #51arrow-up-right
    #47arrow-up-right
    #48arrow-up-right
    #49arrow-up-right
    #53arrow-up-right
    #50arrow-up-right
    #46arrow-up-right
    #46arrow-up-right
    config/app.config.tsarrow-up-right
    #46arrow-up-right
    #46arrow-up-right
    #46arrow-up-right
    #45arrow-up-right
    #44arrow-up-right
    #43arrow-up-right
    #40arrow-up-right
    Remove deprecated gap utilitiesarrow-up-right
    58154f9arrow-up-right
    ee2f5b0arrow-up-right
    0c5a6ccarrow-up-right
    next.config.jsarrow-up-right
    Next.js 9.5+arrow-up-right
    #32arrow-up-right
    #33arrow-up-right
    b402e35arrow-up-right
    #20arrow-up-right
    #12arrow-up-right
    #10arrow-up-right
    #17arrow-up-right
    #18arrow-up-right
    #2arrow-up-right
    #5arrow-up-right
    #4arrow-up-right
    #2arrow-up-right
    huskyarrow-up-right
    @commitlint/cliarrow-up-right
    @commitlint/config-conventionalarrow-up-right
    Conventional Commits specificationarrow-up-right
    #54arrow-up-right
    Tailwind'sarrow-up-right
    layers modearrow-up-right
    #54arrow-up-right
    bdf3b4earrow-up-right
    #42arrow-up-right
    #43arrow-up-right
    #44arrow-up-right
    #44arrow-up-right
    #44arrow-up-right
    #45arrow-up-right
    854d0f8arrow-up-right
    i18nextarrow-up-right
    4b96b61arrow-up-right
    #45arrow-up-right
    #40arrow-up-right
    1332400arrow-up-right
    25fda64arrow-up-right
    397afd6arrow-up-right
    #34arrow-up-right
    rosettaarrow-up-right
    #36arrow-up-right
    76b9c36arrow-up-right
    #19arrow-up-right
    #23arrow-up-right
    MIT licensedarrow-up-right

    Folder Structure

    After creation, your project should look like this:

    The purpose of each of these files and folders are as follows:

    hashtag
    .github

    This folder simply contains the project's Contributing Guidearrow-up-right.

    hashtag
    __tests__

    This folder should contain all tests written. Currently unit tests are provided for each localized version of the template's index page.

    hashtag
    config

    Stores configuration files for most of the starter template's features:

    • i18n/config.ts - Used by our react-i18next integration. You should not modify this file to customize the configuration for your app, instead you should modify app.config.ts.

    • jest/cssTransform.js - Used by our Jest setup to transform .css files.

    • jest/test-utils.tsx - Loaded by each test file to set up the testing framework before each test.

    hashtag
    public

    Stores the following image and json assets:

    • locales - Contains sub-folders for each locale configured for the app, which in turn contain the locale translation files. This is an example of how to configure translation files to leverage i18next's Namespaces feature, more of which you can learn about .

    • favicon.ico, *.png - favicon and application icon files.

    hashtag
    src

    This is where the custom components, pages, Context API providers, typings and utility code for the project live.

    • Non-page components

    hashtag
    styles

    Stores the app's global CSS and CSS/SCSS module files. Feel free to look around at these files to see how easy it is to leverage the Tailwind CSS support integrated with this starter template. Modify/replace the files to suit the needs of your app.

    β”œβ”€β”€ .github
    |   β”œβ”€β”€ contributing.md
    β”œβ”€β”€ __tests__
    |   β”œβ”€β”€ Home-es.test.tsx
    |   β”œβ”€β”€ Home-fr.test.tsx
    |   β”œβ”€β”€ Home.test.tsx
    β”œβ”€β”€ config
    |   β”œβ”€β”€ i18n
    β”‚   β”‚   β”œβ”€β”€ config.ts
    |   β”œβ”€β”€ jest
    β”‚   β”‚   β”œβ”€β”€ cssTransform.js
    β”‚   β”‚   β”œβ”€β”€ test-utils.tsx
    |   β”œβ”€β”€ seo
    β”‚   β”‚   β”œβ”€β”€ next-seo.config.ts
    |   β”œβ”€β”€ app.config.ts
    β”œβ”€β”€ public
    β”‚   β”œβ”€β”€ locales
    |   |   β”œβ”€β”€ en
    |   |   |   β”œβ”€β”€ common.json
    |   |   |   β”œβ”€β”€ footer.json
    |   |   |   β”œβ”€β”€ header.json
    |   |   |   β”œβ”€β”€ index.json
    |   |   β”œβ”€β”€ es
    |   |   |   β”œβ”€β”€ common.json
    |   |   |   β”œβ”€β”€ footer.json
    |   |   |   β”œβ”€β”€ header.json
    |   |   |   β”œβ”€β”€ index.json
    |   |   β”œβ”€β”€ fr
    |   |   |   β”œβ”€β”€ common.json
    |   |   |   β”œβ”€β”€ footer.json
    |   |   |   β”œβ”€β”€ header.json
    |   |   |   β”œβ”€β”€ index.json
    β”‚   β”œβ”€β”€ android-chrome-192x192.png
    β”‚   β”œβ”€β”€ android-chrome-512x512.png
    β”‚   β”œβ”€β”€ apple-touch-icon.png
    β”‚   β”œβ”€β”€ favicon-16x16.png
    β”‚   β”œβ”€β”€ favicon-32x32.png
    β”‚   β”œβ”€β”€ favicon.ico
    β”‚   β”œβ”€β”€ site.webmanifest
    β”‚   β”œβ”€β”€ vercel.svg
    β”œβ”€β”€ src
    |   β”œβ”€β”€ components
    β”‚   β”‚   β”œβ”€β”€ layout
    |   |   |   β”œβ”€β”€ Footer.tsx
    |   |   |   β”œβ”€β”€ Header.tsx
    |   |   |   β”œβ”€β”€ WebApp.tsx
    β”‚   β”‚   β”œβ”€β”€ App.tsx
    β”‚   β”œβ”€β”€ i18n
    β”‚   β”‚   β”œβ”€β”€ create-provider
    |   |   |   β”œβ”€β”€ browser.tsx
    |   |   |   β”œβ”€β”€ index.tsx
    |   β”œβ”€β”€ lib
    β”‚   β”‚   β”œβ”€β”€ types.ts
    β”‚   β”‚   β”œβ”€β”€ utils.ts
    β”‚   β”œβ”€β”€ pages
    β”‚   β”‚   β”œβ”€β”€ [lng]
    |   |   |   β”œβ”€β”€ index.tsx
    β”‚   β”‚   β”œβ”€β”€ api
    |   |   |   β”œβ”€β”€ hello.ts
    β”‚   β”‚   β”œβ”€β”€ 404.tsx
    β”‚   β”‚   β”œβ”€β”€ _app.tsx
    β”‚   β”‚   β”œβ”€β”€ _document.tsx
    β”‚   β”‚   β”œβ”€β”€ _error.tsx
    β”‚   β”‚   β”œβ”€β”€ index.tsx
    β”œβ”€β”€ styles
    |   β”œβ”€β”€ Footer.module.scss
    β”‚   β”œβ”€β”€ Header.module.scss
    |   β”œβ”€β”€ Home.module.scss
    β”‚   β”œβ”€β”€ index.css
    β”œβ”€β”€ .babelrc
    β”œβ”€β”€ .editorconfig
    β”œβ”€β”€ .env.development
    β”œβ”€β”€ .env.production
    β”œβ”€β”€ .gitignore
    β”œβ”€β”€ CODE_OF_CONDUCT.md
    β”œβ”€β”€ README.md
    β”œβ”€β”€ changelog.md
    β”œβ”€β”€ jest.config.js
    β”œβ”€β”€ license.md
    β”œβ”€β”€ next-env.d.ts
    β”œβ”€β”€ next.config.js
    β”œβ”€β”€ package.json
    β”œβ”€β”€ postcss.config.js
    β”œβ”€β”€ tailwind.config.js
    β”œβ”€β”€ tsconfig.json
    └── yarn.lock

    seo/next-seo.config.ts - Configuration file pulled in by our Next SEO integration. You should not modify this file to customize the configuration for your app, instead you should modify app.config.ts.

    site.webmanifest
    - The PWA manifest file.
  • vercel.svg - The Vercel logo that gives us, unaltered.

  • herearrow-up-right
    Page components
    create-next-apparrow-up-right