|
| 1 | +--- |
| 2 | +title: "The create-react-admin CLI" |
| 3 | +--- |
| 4 | + |
| 5 | +import { PackageManagers } from 'starlight-package-managers'; |
| 6 | + |
| 7 | +# `create-react-admin` |
| 8 | + |
| 9 | +Use `create-react-admin` to quickly bootstrap a react-admin project using [Vite](https://vitejs.dev/). It's the preferred way to create a new react-admin application. |
| 10 | + |
| 11 | +<iframe src="https://www.youtube-nocookie.com/embed/i_TbS7quzww" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen style="aspect-ratio: 16 / 9;width:100%;margin-bottom:1em;"></iframe> |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +<PackageManagers type="dlx" pkg="create-react-admin@latest" args="your-admin-name" /> |
| 16 | +Or |
| 17 | +<PackageManagers type="create" pkg="react-admin@latest" args="your-admin-name" /> |
| 18 | + |
| 19 | +This will create an empty react-admin application in a directory called `your-admin-name`, powered by [Vite.js](./Vite.md), and install the dependencies. |
| 20 | + |
| 21 | +You can run the app with: |
| 22 | + |
| 23 | +```sh |
| 24 | +cd your-admin-name |
| 25 | +npm run dev |
| 26 | +``` |
| 27 | + |
| 28 | +**Tip**: If you need to pass extra options, depending on the command you choose you may need to add `--` before the arguments: |
| 29 | + |
| 30 | +<PackageManagers type="dlx" pkg="create-react-admin@latest" args="your-admin-name --interactive" /> |
| 31 | +Or |
| 32 | +<PackageManagers type="create" pkg="react-admin@latest" args="your-admin-name --interactive" /> |
| 33 | + |
| 34 | +```sh |
| 35 | +# `npx` doesn't require the `--` before the arguments |
| 36 | +npx create-react-admin@latest your-admin-name --interactive |
| 37 | +# `npm create` does require the `--` before the arguments |
| 38 | +npm create react-admin@latest your-admin-name -- --interactive |
| 39 | +``` |
| 40 | + |
| 41 | +## Options |
| 42 | + |
| 43 | +The command accepts the following options: |
| 44 | + |
| 45 | +* `--interactive`: Enable the CLI interactive mode |
| 46 | +* `--data-provider`: Set the data provider to use ("data-fakerest", "data-simple-rest", "data-json-server", "supabase" or "none") |
| 47 | +* `--auth-provider`: Set the auth provider to use ("local-auth-provider" or "none") |
| 48 | +* `--resource`: Add a resource that will be initialized with guessers (can be used multiple times). Set to "skip" to bypass the interactive resource step. |
| 49 | +* `--install`: Set the package manager to use for installing dependencies ("yarn", "npm", "bun" or "skip" to bypass the interactive install step) |
| 50 | + |
| 51 | +## `--interactive` |
| 52 | + |
| 53 | +When using this option, the terminal will ask you to choose: |
| 54 | + |
| 55 | +* a [data provider](./DataFetchingGuide.md#the-data-provider) |
| 56 | +* an [auth provider](./DataFetchingGuide.md#authentication) |
| 57 | +* the names of the [resources](./Resource.md) to add |
| 58 | +* the [package manager](#package-manager) to use to install the dependencies |
| 59 | + |
| 60 | +<video controls autoplay playsinline muted loop> |
| 61 | + <source src="./img/create-react-admin.webm" type="video/webm"/> |
| 62 | + <source src="./img/create-react-admin.mp4" type="video/mp4"/> |
| 63 | + Your browser does not support the video tag. |
| 64 | +</video> |
| 65 | + |
| 66 | +## `--data-provider` |
| 67 | + |
| 68 | +`create-react-admin` currently supports five presets for the application's data provider: |
| 69 | + |
| 70 | +* `fakerest`: A client-side data provider that use a JSON object for data, powered by [FakeRest](https://github.com/marmelab/FakeRest). |
| 71 | +* `json-server`: A data provider based on the [JSON Server](https://github.com/typicode/json-server) API |
| 72 | +* `simple-rest`: A data provider for [simple REST APIs](https://github.com/marmelab/react-admin/tree/master/packages/ra-data-simple-rest) |
| 73 | +* `supabase`: A data provider for [Supabase](https://github.com/marmelab/ra-supabase/tree/main/packages/ra-supabase). The auth-provider and resources steps will be skipped. |
| 74 | +* `none` (default): To configure the data provider yourself |
| 75 | + |
| 76 | +You can set your data provider directly with the `--data-provider` option: |
| 77 | + |
| 78 | +```sh |
| 79 | +npx create-react-admin@latest your-admin-name --data-provider json-server |
| 80 | +``` |
| 81 | + |
| 82 | +## `--auth-provider` |
| 83 | + |
| 84 | +`create-react-admin` currently supports two presets to set the application's auth provider which are: |
| 85 | + |
| 86 | +* `local-auth-provider`: Hard coded username/password. |
| 87 | +* `none` (default): No authProvider. |
| 88 | + |
| 89 | +You can set your auth provider directly with the `--auth-provider` option: |
| 90 | + |
| 91 | +```sh |
| 92 | +npx create-react-admin@latest your-admin-name --auth-provider local-auth-provider |
| 93 | +``` |
| 94 | + |
| 95 | +## `--resource` |
| 96 | + |
| 97 | +`create-react-admin` creates an empty app by default. You can initialize CRUD pages for some resources with the `--resource` option: |
| 98 | + |
| 99 | +```sh |
| 100 | +npx create-react-admin@latest your-admin-name --resource posts --resource comments |
| 101 | +``` |
| 102 | + |
| 103 | +**Warning:** the `--resource` flag is incompatible with a `--data-provider supabase` due to a specific [`<AdminGuesser>` component](https://github.com/marmelab/ra-supabase/tree/main/packages/ra-supabase#usage) from `ra-supabase`. |
| 104 | + |
| 105 | +## `--install` |
| 106 | + |
| 107 | +`create-react-admin` can install dependencies using any of the following package managers: |
| 108 | + |
| 109 | +* `npm` (default) |
| 110 | +* `yarn` |
| 111 | +* `bun` |
| 112 | +* `pnpm` |
| 113 | +* `none` (if you want to install dependencies yourself) |
| 114 | + |
| 115 | +You choose an alternative package manager with the `--install` option: |
| 116 | + |
| 117 | +```sh |
| 118 | +npx create-react-admin@latest your-admin-name --install bun |
| 119 | +``` |
0 commit comments