Back to React Router

@react-router/dev (CLI)

docs/api/other-api/dev.md

7.6.27.3 KB
Original Source

React Router CLI

The React Router CLI comes from the @react-router/dev package. Make sure it is in your package.json devDependencies so it doesn't get deployed to your server.

To get a full list of available commands and flags, run:

shellscript
npx @react-router/dev -h

react-router build

Builds your app for production with Vite. This command will set process.env.NODE_ENV to production and minify the output for deployment.

shellscript
react-router build
FlagDescriptionTypeDefault
--assetsInlineLimitStatic asset base64 inline threshold in bytesnumber4096
--clearScreenAllow/disable clear screen when loggingboolean
--config, -cUse specified config filestring
--emptyOutDirForce empty outDir when it's outside of rootboolean
--logLevel, -lUse specified log level"info" | "warn" | "error" | "silent" | string
--minifyEnable/disable minification, or specify minifier to useboolean | "terser" | "esbuild""esbuild"
--mode, -mSet env modestring
--profileStart built-in Node.js inspector
--sourcemapClientOutput source maps for client buildboolean | "inline" | "hidden"false
--sourcemapServerOutput source maps for server buildboolean | "inline" | "hidden"false

react-router dev

Runs your app in development mode with HMR and Hot Data Revalidation (HDR), powered by Vite.

shellscript
react-router dev
<docs-info>

What is "Hot Data Revalidation"?

Like HMR, HDR is a way of hot updating your app without needing to refresh the page. That way you can keep your app state as your edits are applied in your app. HMR handles client-side code updates like when you change the components, markup, or styles in your app. Likewise, HDR handles server-side code updates.

That means any time you make a change to the current page (or any code that your current page depends on), React Router will re-fetch data from your loaders. That way your app is always up to date with the latest code changes, client-side or server-side.

</docs-info>
FlagDescriptionTypeDefault
--clearScreenAllow/disable clear screen when loggingboolean
--config, -cUse specified config filestring
--corsEnable CORSboolean
--forceForce the optimizer to ignore the cache and re-bundleboolean
--hostSpecify hostnamestring
--logLevel, -lUse specified log level"info" | "warn" | "error" | "silent" | string
--mode, -mSet env modestring
--openOpen browser on startupboolean | string
--portSpecify portnumber
--profileStart built-in Node.js inspector
--strictPortExit if specified port is already in useboolean

react-router reveal

React Router handles the entry points of your application by default.

If you want to have control over these entry points, you can run npx react-router reveal to generate the entry.client.tsx and entry.server.tsx files in your app directory. When these files are present, React Router will use them instead of the defaults.

shellscript
npx react-router reveal
FlagDescriptionTypeDefault
--config, -cUse specified config filestring
--mode, -mSet env modestring
--no-typescriptGenerate plain JavaScript filesbooleanfalse
--typescriptGenerate TypeScript filesbooleantrue

react-router routes

Prints the routes in your app to the terminal.

shellscript
react-router routes

Your route tree will be in a JSX format by default. You can also use the --json flag to get the routes in a JSON format.

shellscript
react-router routes --json
FlagDescriptionTypeDefault
--config, -cUse specified config filestring
--jsonOutput routes in JSON formatbooleanfalse
--mode, -mSet env modestring

react-router typegen

Generates TypeScript types for your routes. This happens automatically during development, but you can manually run it when needed, e.g., to generate types in CI before running tsc. See Type Safety for more information.

shellscript
react-router typegen
FlagDescriptionTypeDefault
--config, -cUse specified config filestring
--mode, -mSet env modestring
--watchWatch for changesbooleanfalse