|
| 1 | +# Starter React app that builds as a single HTML file |
| 2 | + |
| 3 | +An app written with React, TypeScript, and Vite that builds as a single `index.html` file. |
| 4 | + |
| 5 | +A one-file bundle doesn't make sense for most production applications, but it's handy for creating internal tools and prototypes that are easy to share, with no env setup required. |
| 6 | + |
| 7 | +## UX components and styles |
| 8 | + |
| 9 | +The project has ready-to-use UI components such as buttons and tabs, thanks to [Material UI](https://mui.com/material-ui). It also includes [Emotion](https://emotion.sh/docs/introduction) for styling your own components. |
| 10 | + |
| 11 | +## Data storage and access |
| 12 | + |
| 13 | +The app can access and use any data you provide in JSON format. The app can't write persistent data, though you could use something like `localStorage` for that if you needed to. |
| 14 | + |
| 15 | +The app's "database" is [a `.ts` file](src/db.ts) that you can update with your own data (or replace programmatically) before building the app. Any data you store in that file will be available in [the `App` component](src/App.tsx) as `dbData`. |
| 16 | + |
| 17 | +## Limitations |
| 18 | + |
| 19 | +The app uses [vite-plugin-singlefile](https://github.com/richardtallent/vite-plugin-singlefile) (thanks, Richard Tallent!), so any limitations documented in the plugin's README apply to this app as well. |
| 20 | + |
| 21 | +## Setup and usage instructions |
| 22 | + |
| 23 | +### 1. Clone the repository |
| 24 | + |
| 25 | +```shell |
| 26 | +git clone [email protected]:jhgilbert/single-file-react-app.git |
| 27 | +cd single-file-react-app |
| 28 | +``` |
| 29 | + |
| 30 | +### 2. Install dependencies |
| 31 | + |
| 32 | +```shell |
| 33 | +npm install |
| 34 | +``` |
| 35 | + |
| 36 | +### 3. Run the development version |
| 37 | + |
| 38 | +```shell |
| 39 | +npm run dev |
| 40 | +``` |
| 41 | + |
| 42 | +You should see output that looks something like this: |
| 43 | + |
| 44 | +```shell |
| 45 | + VITE v5.4.10 ready in 92 ms |
| 46 | + |
| 47 | + ➜ Local: http://localhost:5173/ |
| 48 | + ➜ Network: use --host to expose |
| 49 | + ➜ press h + enter to show help |
| 50 | +``` |
| 51 | + |
| 52 | +In your browser, visit the provided address (`http://localhost:5173` in the above example), and you should see a demo page. |
| 53 | + |
| 54 | +### 4. Make and preview changes |
| 55 | + |
| 56 | +Try changing some of the verbiage in `src/App.tsx`. The app should immediately reload, and you should see the changes in your browser. |
| 57 | + |
| 58 | +### 5. Build and start the "production" version of the app |
| 59 | + |
| 60 | +Run `npm run prod` to build the `dist/index.html` file as it will work in production. `dist/index.html` contains all of the code necessary to run your app, and opens in your browser automatically once the build is finished. |
| 61 | + |
| 62 | +To just build the file without launching it, you can use `npm run build` instead. |
| 63 | + |
| 64 | +### 6. Share the app |
| 65 | + |
| 66 | +Once you've verified in staging that the file is working as expected, it's ready to be shared. **Make sure to share `dist/index.html`, not the root `index.html`.** The latter file is compiled to `dist/index.html` in the build process. |
0 commit comments