Skip to content

Up and running with ZEIT's Next.js framework for server-rendered React apps, Tachyons CSS framework, ESlint, JavaScript Standard Style for React, Flow, Jest and Microsoft Visual Studio Code.

License

Notifications You must be signed in to change notification settings

ajaykurien/nextjs-starter-kit

Repository files navigation

Next.js Starter Kit

Up and running with ZEIT's Next.js framework for server-rendered React apps, Tachyons CSS framework, ESlint and JavaScript Standard Style, Jest and Microsoft Visual Studio Code.

Contents

Installation

  1. Get the latest version:
$ git clone -o nextjs-starter-kit -b master --single-branch \
      https://github.com/ajaykurien/nextjs-starter-kit.git MyNextApp
$ cd MyNextApp
  1. Install the project dependencies and the developer tools specified in package.json
$ npm install
  1. Start Next.js' dev server at http://localhost:3000
$ npm run dev
  1. Follow the documentation at ZEIT/Next.js to add pages, static files, JavaScript modules and React components to build your universal app or static site.

Tools, plugins, set-up and commands...

(Information only: the following is an aide de memoire for me; please follow the Installation instructions above)

Tool setup

Set up working directory and git repo:

$ mkdir MyNextJSApp && cd $_
$ git init
$ touch .gitignore
$ git add *
$ git commit -m "Initialised repo."

Initialise a new project:

$ npm init

Install production libraries:

$ npm install next react react-dom classnames

Add flow...

$ npm install -D flow-bin eslint-plugin-flowtype
$ flow init
$ mkdir types
$ curl "https://raw.githubusercontent.com/zeit/next.js/master/examples/with-flow/types/next.js.flow" > types/next.js.flow

Add some entries to .flowconfig...

[libs]
types/

and in .babelrc:

{
  "presets": ["next/babel"],
  "plugins": ["transform-flow-strip-types"]
}

Install and configure linters:

$ npm install -D eslint babel-eslint babel-plugin-transform-flow-strip-types eslint-config-standard eslint-config-standard-react eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node eslint-plugin-react

Configure the newly-created eslintrc.js:

module.exports = {
  extends: ['standard', 'standard-react'],
  parser: 'babel-eslint',
  plugins: ['react', 'flow'],
  rules: {
    'jsx-quotes': ['error', 'prefer-double'] // follow Facebook's convention for double quotes in JSX attributes.
  }
}

Install and configure Jest test framework:

$ npm install -D jest

Set up Zeit/Next.js (instructions):

  • Create folders for pages (required), static files, site-wide utilities, and React components:
$ mkdir pages static lib components config
$ touch pages/.gitkeep static/.gitkeep lib/.gitkeep components/.gitkeep config/.gitkeep
  • Create the main entry point and a custom wrapper for common page elements:
$ touch pages/index.js pages/_document.js
  • Add the core HTML that will appear on every page, including the Tachyons CSS library:
/* pages/_document.js */
import Document, { Head, Main, NextScript } from 'next/document'
import React from 'react'

import flush from 'styled-jsx/server'

export default class MyDocument extends Document {
  static getInitialProps ({ renderPage }) {
    const { html, head, errorHtml, chunks } = renderPage()
    const styles = flush()
    return { html, head, errorHtml, chunks, styles }
  }

  render () {
    return (
      <html>
        <Head>
          <meta name="viewport" content="width=device-width, initial-scale=1" />
          <link
            rel="stylesheet"
            href="https://unpkg.com/tachyons@4.8.0/css/tachyons.min.css"
          />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </html>
    )
  }
}

TODO

About

Up and running with ZEIT's Next.js framework for server-rendered React apps, Tachyons CSS framework, ESlint, JavaScript Standard Style for React, Flow, Jest and Microsoft Visual Studio Code.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published