-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add docs for react-router CLI #14148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
markdalgleish
wants to merge
1
commit into
main
Choose a base branch
from
markdalgleish/dev-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,124 @@ | ||||||||||||
--- | ||||||||||||
title: "@react-router/dev (CLI)" | ||||||||||||
--- | ||||||||||||
|
||||||||||||
# 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 nonumber | ||||||||||||
npx @react-router/dev -h | ||||||||||||
``` | ||||||||||||
|
||||||||||||
## `react-router build` | ||||||||||||
|
||||||||||||
Builds your app for production with [Vite][vite]. This command will set `process.env.NODE_ENV` to `production` and minify the output for deployment. | ||||||||||||
|
||||||||||||
```shellscript nonumber | ||||||||||||
react-router build | ||||||||||||
``` | ||||||||||||
|
||||||||||||
| Flag | Description | Type | Default | | ||||||||||||
| --------------------- | ------------------------------------------------------- | --------------------------------------------------- | ----------- | | ||||||||||||
| `--assetsInlineLimit` | Static asset base64 inline threshold in bytes | `number` | `4096` | | ||||||||||||
| `--clearScreen` | Allow/disable clear screen when logging | `boolean` | | | ||||||||||||
| `--config`, `-c` | Use specified config file | `string` | | | ||||||||||||
| `--emptyOutDir` | Force empty outDir when it's outside of root | `boolean` | | | ||||||||||||
| `--logLevel`, `-l` | Use specified log level | `"info" \| "warn" \| "error" \| "silent" \| string` | | | ||||||||||||
| `--minify` | Enable/disable minification, or specify minifier to use | `boolean \| "terser" \| "esbuild"` | `"esbuild"` | | ||||||||||||
| `--mode`, `-m` | Set env mode | `string` | | | ||||||||||||
| `--profile` | Start built-in Node.js inspector | | | | ||||||||||||
| `--sourcemapClient` | Output source maps for client build | `boolean \| "inline" \| "hidden"` | `false` | | ||||||||||||
| `--sourcemapServer` | Output source maps for server build | `boolean \| "inline" \| "hidden"` | `false` | | ||||||||||||
|
||||||||||||
## `react-router dev` | ||||||||||||
|
||||||||||||
Runs your app in development mode with HMR and Hot Data Revalidation (HDR), powered by [Vite][vite]. | ||||||||||||
|
||||||||||||
```shellscript nonumber | ||||||||||||
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][loaders]. | ||||||||||||
That way your app is _always_ up-to-date with the latest code changes, client-side or server-side. | ||||||||||||
|
||||||||||||
</docs-info> | ||||||||||||
|
||||||||||||
| Flag | Description | Type | Default | | ||||||||||||
| ------------------ | ----------------------------------------------------- | --------------------------------------------------- | ------- | | ||||||||||||
| `--clearScreen` | Allow/disable clear screen when logging | `boolean` | | | ||||||||||||
| `--config`, `-c` | Use specified config file | `string` | | | ||||||||||||
| `--cors` | Enable CORS | `boolean` | | | ||||||||||||
| `--force` | Force the optimizer to ignore the cache and re-bundle | `boolean` | | | ||||||||||||
| `--host` | Specify hostname | `string` | | | ||||||||||||
| `--logLevel`, `-l` | Use specified log level | `"info" \| "warn" \| "error" \| "silent" \| string` | | | ||||||||||||
| `--mode`, `-m` | Set env mode | `string` | | | ||||||||||||
| `--open` | Open browser on startup | `boolean \| string` | | | ||||||||||||
| `--port` | Specify port | `number` | | | ||||||||||||
| `--profile` | Start built-in Node.js inspector | | | | ||||||||||||
| `--strictPort` | Exit if specified port is already in use | `boolean` | | | ||||||||||||
|
||||||||||||
## `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 nonumber | ||||||||||||
npx react-router reveal | ||||||||||||
``` | ||||||||||||
|
||||||||||||
| Flag | Description | Type | Default | | ||||||||||||
| ----------------- | ------------------------------- | --------- | ------- | | ||||||||||||
| `--config`, `-c` | Use specified config file | `string` | | | ||||||||||||
| `--mode`, `-m` | Set env mode | `string` | | | ||||||||||||
| `--no-typescript` | Generate plain JavaScript files | `boolean` | `false` | | ||||||||||||
| `--typescript` | Generate TypeScript files | `boolean` | `true` | | ||||||||||||
|
||||||||||||
## `react-router routes` | ||||||||||||
|
||||||||||||
Prints the routes in your app to the terminal. | ||||||||||||
|
||||||||||||
```shellscript nonumber | ||||||||||||
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 nonumber | ||||||||||||
react-router routes --json | ||||||||||||
``` | ||||||||||||
|
||||||||||||
| Flag | Description | Type | Default | | ||||||||||||
| ---------------- | ---------------------------- | --------- | ------- | | ||||||||||||
| `--config`, `-c` | Use specified config file | `string` | | | ||||||||||||
| `--json` | Output routes in JSON format | `boolean` | `false` | | ||||||||||||
| `--mode`, `-m` | Set env mode | `string` | | | ||||||||||||
|
||||||||||||
## `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`. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth a cross-link to https://reactrouter.com/explanation/type-safety somewhere in here?
Suggested change
|
||||||||||||
|
||||||||||||
```shellscript nonumber | ||||||||||||
react-router typegen | ||||||||||||
``` | ||||||||||||
|
||||||||||||
| Flag | Description | Type | Default | | ||||||||||||
| ---------------- | ------------------------- | --------- | ------- | | ||||||||||||
| `--config`, `-c` | Use specified config file | `string` | | | ||||||||||||
| `--mode`, `-m` | Set env mode | `string` | | | ||||||||||||
| `--watch` | Watch for changes | `boolean` | `false` | | ||||||||||||
|
||||||||||||
[loaders]: ../../start/framework/data-loading | ||||||||||||
[vite]: https://vite.dev | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.