Skip to content

Commit

Permalink
Port the project from Create React App to Vite.
Browse files Browse the repository at this point in the history
The thing prompting this now is that our deployments are broken because CRA is giving us obscure build errors for some of our newer dependencies, like @radix-ui/themes. This is apparently caused by outdated dependencies within CRA's toolchain. (radix-ui/themes#104, facebook/create-react-app#11767, and similar.) It's unclear if or when CRA is going to update those dependencies. From reactjs/react.dev#5487 (comment) and the lack of CRA releases since then, it seems like people generally aren't holding their breath.

I can't discern whether Vite is just JS framework hype, but for now at least, it seems easier to port to it than to keep limping along with CRA.

So, to do the port:

* Replace CRA's config files with the defaults from `npm create vite@latest`.
* Delete all the Progressive Web App stuff from CRA. We're not worrying about that for now.
* Update package.json...
  * Add `"type": "module"` per https://vitejs.dev/guide/troubleshooting.html#cjs.
  * Update scripts and dependencies per `npm create vite@latest`. Drop various testing-library dependencies added by CRA, since we weren't using them.
  * Separate dependencies from devDependencies while we're here, just for human organization.
* Replace CRA's default readme with Vite's default readme.
* Port unit tests from Jest to Vitest. This just involves using explicit imports for the globals like `it` and `expect`.
  • Loading branch information
SyntaxColoring committed Nov 22, 2023
1 parent 898a6bc commit 4aa5487
Show file tree
Hide file tree
Showing 21 changed files with 5,020 additions and 17,193 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/coverage

# production
/build
/dist

# misc
.DS_Store
Expand Down
60 changes: 22 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
# Getting Started with Create React App
# React + TypeScript + Vite

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

## Available Scripts
Currently, two official plugins are available:

In the project directory, you can run:
- [@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
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

### `npm start`
## Expanding the ESLint configuration

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

The page will reload if you make edits.\
You will also see any lint errors in the console.
- Configure the top-level `parserOptions` property like this:

### `npm test`
```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en" class="full-height">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Log Viewer</title>
</head>
<body class="full-height">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root" class="full-height"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>

0 comments on commit 4aa5487

Please sign in to comment.