|
| 1 | +# Forum One Next.js Starter App |
| 2 | + |
| 3 | +This is a starter app for [Next.js](https://nextjs.org/) (bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app)) that includes the following features: |
| 4 | +* [TypeScript](https://www.typescriptlang.org/) |
| 5 | +* [Emotion](https://emotion.sh/docs/introduction) |
| 6 | +* [ESLint](https://eslint.org/) |
| 7 | +* [Prettier](https://prettier.io/) |
| 8 | + |
| 9 | +Note that Next v11 comes with the following installed already: |
| 10 | +* [Webpack v5](https://webpack.js.org/concepts/) |
| 11 | +* [Babel v7](https://babeljs.io/docs/en/) |
| 12 | + |
| 13 | +## Getting Started |
| 14 | + |
| 15 | +Ensure that you are using the proper Node version for this app. We currently use v16. Assuming you have [nvm](https://github.com/nvm-sh/nvm) installed locally, you can simply run: |
| 16 | + |
| 17 | +```bash |
| 18 | +nvm use |
| 19 | +``` |
| 20 | + |
| 21 | +This will set your Node version to match the `.nvmrc` file. |
| 22 | + |
| 23 | +Next, install packages: |
| 24 | +```bash |
| 25 | +npm ci |
| 26 | +``` |
| 27 | + |
| 28 | +To run the [development server](https://nextjs.org/docs/api-reference/cli#development): |
| 29 | + |
| 30 | +```bash |
| 31 | +npm run dev |
| 32 | +``` |
| 33 | + |
| 34 | +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. |
| 35 | + |
| 36 | +## Other Commands |
| 37 | + |
| 38 | +### Build production application |
| 39 | + |
| 40 | +```bash |
| 41 | +npm run build |
| 42 | +``` |
| 43 | +Runs `next build`, which builds the production application in the `.next` folder. For more information, see the [Next.js CLI documentation](https://nextjs.org/docs/api-reference/cli#build). |
| 44 | + |
| 45 | +### Start application in production mode |
| 46 | + |
| 47 | +```bash |
| 48 | +npm run start |
| 49 | +``` |
| 50 | + |
| 51 | +Runs `next start`, which starts a Node.js server that supports [hybrid pages](https://nextjs.org/docs/basic-features/pages), serving both statically generated and server-side rendered pages. Note that `npm run build` should be ran first. For more information, see the [Next.js CLI documentation](https://nextjs.org/docs/api-reference/cli#production). |
| 52 | + |
| 53 | +### Export application to static HTML |
| 54 | + |
| 55 | +```bash |
| 56 | +npm run export |
| 57 | +``` |
| 58 | + |
| 59 | +Runs `next build && next export`. This allows you to export your app to static HTML (exported in the `out` folder), which can be run standalone without the need of a Node.js server. For more information, see the [Next.js Static HTML Export documentation](https://nextjs.org/docs/advanced-features/static-html-export). |
| 60 | + |
| 61 | +### Run linter |
| 62 | + |
| 63 | +```bash |
| 64 | +npm run lint |
| 65 | +``` |
| 66 | + |
| 67 | +Runs `next lint`, which runs the ESLint command. This is useful to catch lint errors that you might miss during development. For more information, see the [Next.js ESLint documentation](https://nextjs.org/docs/basic-features/eslint). |
| 68 | + |
| 69 | +### Run prettier |
| 70 | + |
| 71 | +#### Prettier check |
| 72 | + |
| 73 | +```bash |
| 74 | +npm run prettier |
| 75 | +``` |
| 76 | + |
| 77 | +Runs `prettier --check`, which will check that all files within the `pages` and `source` directories use the Prettier code style from `.prettierrc`. This might be redundant with the `lint` script above, since it extends whatever Prettier rules we have set. |
| 78 | + |
| 79 | +#### Prettier write |
| 80 | + |
| 81 | +```bash |
| 82 | +npm run prettier:write |
| 83 | +``` |
| 84 | + |
| 85 | +Runs `prettier --write`, which will find and fix all prettier issues found within the `pages` and `source` directories. Note that this will automatically overwrite your files. |
| 86 | + |
| 87 | +### Run TypeScript compiler (tsc) |
| 88 | + |
| 89 | +```bash |
| 90 | +npm run tsc |
| 91 | +``` |
| 92 | + |
| 93 | +Runs `tsc --noEmit`, which will compile the TypeScript code without emitting files. This acts as a TS error check in your CLI. This is useful to catch TS errors that you might miss during development. For more information, see the [TypeScript Compiler (tsc) documentation](https://www.typescriptlang.org/docs/handbook/compiler-options.html). |
| 94 | + |
| 95 | +### Scaffold new component |
| 96 | + |
| 97 | +```bash |
| 98 | +npm run component |
| 99 | +``` |
| 100 | +Runs the `lib/component.js` script, which will scaffold a new React or Emotion component, |
| 101 | +with the option to include a Storybook story file as well. |
| 102 | + |
| 103 | +## Husky |
| 104 | + |
| 105 | +This project uses [Husky](https://typicode.github.io/husky/#/) to check code on git commits. By default, it is setup to use the `npm test` script which runs `lint` and `tsc` (TypeScript) checks against the codebase. This check occurs on `git commit` attempts. This helps developers catch errors _before_ pushing branches and creating PRs, quickening the overall dev worklow. |
| 106 | + |
| 107 | +To bypass this check, you can use the `--no-verify` flag with your commit: |
| 108 | + |
| 109 | +```bash |
| 110 | +git commit -m "This will not get checked by Husky." --no-verify |
| 111 | +``` |
| 112 | + |
| 113 | +Note that bypassing the Husky check is frowned upon. |
| 114 | + |
| 115 | +## Notes |
| 116 | + |
| 117 | +* Code for the app is currently configured to go into the `pages` directory (for [Next.js pages](https://nextjs.org/docs/basic-features/pages)) and `source` for theming, components, providers, helpers, etc. |
| 118 | +* Starting in Next.js v9.4, TypeScript errors do not show up in your browser when running the dev server (i.e. `npm run dev`). However, TS errors will prevent `next build` (i.e. `npm run build`) from running successfully. Be sure to run `npm run lint` and `npm run tsc` before committing and pushing code. This will give you lint and TS errors that will most likely cause your builds to fail. |
| 119 | + * For discussion: should we include a [TS checker in the config](https://github.com/vercel/next.js/issues/12735#issuecomment-629404102)? Note that a Next.js dev warns that [this will greatly slow development](https://github.com/vercel/next.js/issues/12735#issuecomment-629404842). |
| 120 | +* The current favicon implementation will probably not display correctly locally in Chrome (v94), but does display correctly in Firefox and Safari. Note that the favicon _does_ display correctly once deployed. Not sure why. |
0 commit comments