Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 23 additions & 87 deletions react_app_demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,120 +3,56 @@
#### Instructions for Running

1. Clone this repo.
```sh
git clone https://github.com/silvia-odwyer/photon
```

2. Navigate to `crate` and run `wasm-pack build`. Ensure you have wasm-pack installed.

```sh
cd crate
wasm-pack build
```

This will create an npm package, which can be found in `crate/pkg`.

3. Navigate to pkg, and run `npm link`.

```sh
cd pkg
npm link
git clone https://github.com/silvia-odwyer/photon
```

5. Then, navigate to this dir, and install dependencies.

2. Install the demo dependencies.
```sh
cd ../../react_app_demo
cd react_app_demo
npm install
```

This app also requires changing the project's webpack.config.js to load WASM files; however this can't be done
without ejecting, so to combat this, I used react-app-rewired to allow for overriding the webpack config.

Install react-app-rewired and wasm-loader:

3. Start a development server at localhost:5173.
```sh
npm install react-app-rewired wasm-loader -D
npm run dev
```
Vite will open the app in your browser and hot-reload when you edit sources.

4. Run `npm link photon`.
```sh
npm link photon
```

6. Start a development server at localhost:3000

4. Build an optimised production bundle.
```sh
npm run start
npm run build
```
Use `npm run preview` to verify the build locally, or `npm run lint` to run TypeScript in no-emit mode.

### Create React App Notes
> Want to test against a locally compiled Photon crate? Run `wasm-pack build` inside `crate/` and point the demo at the generated `crate/pkg` output (e.g. via `npm link`).

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
### Vite + React Notes

This project is bootstrapped with [Vite](https://vitejs.dev/) and React 19 with TypeScript. The Photon WebAssembly package is loaded directly from npm and initialised before the UI becomes interactive.

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
### `npm run dev`

The page will reload if you make edits.<br>
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
Runs the app in development mode at [http://localhost:5173](http://localhost:5173) with hot module replacement.

### `npm run build`

Builds the app for production to the `build` folder.<br>
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.<br>
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`
Generates a production-ready bundle in `dist/` and runs the TypeScript compiler as part of the build pipeline.

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

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.
Serves the production bundle locally so you can sanity-check the optimised output.

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.
### `npm run lint`

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.
Type-checks the project (`tsc --noEmit`) without writing any build artifacts.

## 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/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
- [Photon documentation](https://silvia-odwyer.github.io/photon/docs/photon/index.html)
- [Vite documentation](https://vitejs.dev/guide/)
- [React documentation](https://react.dev/)
25 changes: 0 additions & 25 deletions react_app_demo/config-overrides.js

This file was deleted.

17 changes: 17 additions & 0 deletions react_app_demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Photon React Demo</title>
<meta
name="description"
content="Photon WebAssembly demo powered by React + TypeScript."
/>
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
45 changes: 16 additions & 29 deletions react_app_demo/package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
{
"name": "photon-react-app",
"version": "0.1.0",
"name": "photon-react-demo",
"version": "1.0.0",
"private": true,
"dependencies": {
"@silvia-odwyer/photon": "^0.1.0",
"@silvia-odwyer/photon-node": "^0.1.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"wasm-worker": "^0.4.0"
},
"type": "module",
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test"
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "tsc --noEmit"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"dependencies": {
"@silvia-odwyer/photon": "^0.3.3",
"react": "^19.1.1",
"react-dom": "^19.1.1"
},
"devDependencies": {
"react-app-rewired": "^2.1.3",
"wasm-loader": "^1.3.0"
"@types/react": "^19.1.13",
"@types/react-dom": "^19.1.9",
"@vitejs/plugin-react": "^5.0.3",
"typescript": "^5.9.2",
"vite": "^7.1.6"
}
}
Loading