|
| 1 | +# ReactMD + TypeScript + Vite |
| 2 | + |
| 3 | +This template provides a minimal setup to get ReactMD working in Vite with HMR and some ESLint rules. |
| 4 | + |
| 5 | +## What's Included |
| 6 | + |
| 7 | +This example will setup an example Create React App + ReactMD app that has the following features: |
| 8 | + |
| 9 | +- [\_everything.scss](./src/_everything.scss) to override the default `react-md` theme and feature toggles |
| 10 | +- [RootLayout](./src/components/RootLayout.tsx) that initializes a base layout for the app |
| 11 | + - [MainNavigation](./src/components/MainNavigation.tsx) as an example navigation panel |
| 12 | +- [rmdConfig](./src/rmdConfig.tsx) to configure icons and other global settings in `react-md` |
| 13 | + |
| 14 | +## How to Use |
| 15 | + |
| 16 | +Download the example: |
| 17 | + |
| 18 | +```bash |
| 19 | +curl https://codeload.github.com/mlaursen/react-md/tar.gz/main | tar -xz --strip=2 react-md-main/examples/vite-ts |
| 20 | +cd vite-ts |
| 21 | +``` |
| 22 | + |
| 23 | +Install it and run: |
| 24 | + |
| 25 | +```sh |
| 26 | +npm install |
| 27 | +npm run dev |
| 28 | +``` |
| 29 | + |
| 30 | +Finally, initialize the git repo and create your first commit: |
| 31 | + |
| 32 | +```sh |
| 33 | +git init |
| 34 | +git add . |
| 35 | +git commit -m "Initial commit" |
| 36 | +``` |
| 37 | + |
| 38 | +## Vite |
| 39 | + |
| 40 | +Currently, two official plugins are available: |
| 41 | + |
| 42 | +- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh |
| 43 | +- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
| 44 | + |
| 45 | +## Expanding the ESLint configuration |
| 46 | + |
| 47 | +If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules: |
| 48 | + |
| 49 | +```js |
| 50 | +export default tseslint.config({ |
| 51 | + extends: [ |
| 52 | + // Remove ...tseslint.configs.recommended and replace with this |
| 53 | + ...tseslint.configs.recommendedTypeChecked, |
| 54 | + // Alternatively, use this for stricter rules |
| 55 | + ...tseslint.configs.strictTypeChecked, |
| 56 | + // Optionally, add this for stylistic rules |
| 57 | + ...tseslint.configs.stylisticTypeChecked, |
| 58 | + ], |
| 59 | + languageOptions: { |
| 60 | + // other options... |
| 61 | + parserOptions: { |
| 62 | + project: ['./tsconfig.node.json', './tsconfig.app.json'], |
| 63 | + tsconfigRootDir: import.meta.dirname, |
| 64 | + }, |
| 65 | + }, |
| 66 | +}) |
| 67 | +``` |
| 68 | + |
| 69 | +You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules: |
| 70 | + |
| 71 | +```js |
| 72 | +// eslint.config.js |
| 73 | +import reactX from 'eslint-plugin-react-x' |
| 74 | +import reactDom from 'eslint-plugin-react-dom' |
| 75 | + |
| 76 | +export default tseslint.config({ |
| 77 | + plugins: { |
| 78 | + // Add the react-x and react-dom plugins |
| 79 | + 'react-x': reactX, |
| 80 | + 'react-dom': reactDom, |
| 81 | + }, |
| 82 | + rules: { |
| 83 | + // other rules... |
| 84 | + // Enable its recommended typescript rules |
| 85 | + ...reactX.configs['recommended-typescript'].rules, |
| 86 | + ...reactDom.configs.recommended.rules, |
| 87 | + }, |
| 88 | +}) |
| 89 | +``` |
0 commit comments