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.
react
,react-dom
: Facebook's JavaScript UI librarynext
: ZEIT's framework for server-rendered React appsTachyons
: atomic CSS components frameworkeslint
: Pluggable linting utility for JavaScript and JSXeslint-config-standard-react
: ESLint config for React/JSX support in JavaScript Standard Styleflow
: Facebook's static type checker for JavaScriptjest
: Facebook's JavaScript code testing platformclassnames
: Jed Watson's JavaScript utility for conditionally joining class names together
- 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
- Install the project dependencies and the developer tools specified in
package.json
$ npm install
- Start Next.js' dev server at
http://localhost:3000
$ npm run dev
- 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.
- Create
next.config.js
file and customise Next.js' behaviour. - Create
now.json
and configure the app's deployment on now
- Create
(Information only: the following is an aide de memoire for me; please follow the Installation instructions above)
- Microsoft Visual Studio Code, plus plugins:
- Auto Close Tag automatically adds closing HTML & XML tags.
- Auto Rename Tag automatically renames pairs of HTML & XML tags.
- npm support for VS Code validates installed
npm
modules against the dependencies specified inpackage.json
. - npm Intellisense autocompletes names of npm modules in
import
statements. - Debugger for Chrome debug JavaScript code running in Google Chrome from inside VS Code.
- ESLint integrates ESLint into VS Code
- ES7 React/Redux/React-Native/JS snippets snippets in ES7 for Javascript and React/Redux, with
babel-plugin
features. - Flow Language Support adds Flow support.
- Document This automatically generates detailed JSDoc comments for both TypeScript and JavaScript files.
- exports autocomplete collects ES6 exports from your project and autocompletes them.
$ mkdir MyNextJSApp && cd $_
$ git init
$ touch .gitignore
$ git add *
$ git commit -m "Initialised repo."
$ npm init
$ npm install next react react-dom classnames
$ 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
[libs]
types/
{
"presets": ["next/babel"],
"plugins": ["transform-flow-strip-types"]
}
$ 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
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.
}
}
$ 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>
)
}
}
- Automate the setup process, inspired by segmentio/create-next-app:
- Use
Inquirer.js
andmerge-config
in npmpostinstall
scripts to take command line arguments and customise the setup.
- Use