|
1 | | -# ${bsb:name} |
| 1 | +# ReasonReact Template & Examples |
2 | 2 |
|
3 | | -## Run Project |
| 3 | +This is: |
| 4 | +- A template for your new ReasonReact project. |
| 5 | +- A collection of thin examples illustrating ReasonReact usage. |
| 6 | +- Extra helper documentation for ReasonReact (full ReasonReact docs [here](https://reasonml.github.io/reason-react/)). |
| 7 | + |
| 8 | +`src` contains 4 sub-folders, each an independent, self-contained ReasonReact example. Feel free to delete any of them and shape this into your project! This template's more malleable than you might be used to =). |
| 9 | + |
| 10 | +The point of this template and examples is to let you understand and personally tweak the entirely of it. We **don't** give you an opaque, elaborate mega build setup just to put some boxes on the screen. It strikes to stay transparent, learnable, and simple. You're encouraged to read every file; it's a great feeling, having the full picture of what you're using and being able to touch any part. |
| 11 | + |
| 12 | +## Run |
4 | 13 |
|
5 | 14 | ```sh |
6 | 15 | npm install |
| 16 | +npm run server |
| 17 | +# in a new tab |
7 | 18 | npm start |
8 | | -# in another tab |
9 | | -npm run webpack |
10 | 19 | ``` |
11 | 20 |
|
12 | | -After you see the webpack compilation succeed (the `npm run webpack` step), open up `build/index.html` (**no server needed!**). Then modify whichever `.re` file in `src` and refresh the page to see the changes. |
| 21 | +Open a new web page to `http://localhost:8000/`. Change any `.re` file in `src` to see the page auto-reload. **You don't need any bundler when you're developing**! |
13 | 22 |
|
14 | | -**For more elaborate ReasonReact examples**, please see https://github.com/reasonml-community/reason-react-example |
| 23 | +**How come we don't need any bundler during development**? We highly encourage you to open up `index.html` to check for yourself! |
15 | 24 |
|
16 | | -## Run Project with Server |
| 25 | +# Features Used |
17 | 26 |
|
18 | | -To run with the webpack development server run `npm run server` and view in the browser at http://localhost:8000. Running in this environment provides hot reloading and support for routing; just edit and save the file and the browser will automatically refresh. |
| 27 | +| | Blinking Greeting | Reducer from ReactJS Docs | Fetch Dog Pictures | Reason Using JS Using Reason | |
| 28 | +|---------------------------|------------------|----------------------------|--------------------|------------------------------| |
| 29 | +| No props | | ✓ | | | |
| 30 | +| Has props | | | | ✓ | |
| 31 | +| Children props | ✓ | | | | |
| 32 | +| No state | | | | ✓ | |
| 33 | +| Has state | ✓ | | ✓ | | |
| 34 | +| Has state with useReducer | | ✓ | | | |
| 35 | +| ReasonReact using ReactJS | | | | ✓ | |
| 36 | +| ReactJS using ReasonReact | | | | ✓ | |
| 37 | +| useEffect | ✓ | | ✓ | | |
| 38 | +| Dom attribute | ✓ | ✓ | | ✓ | |
| 39 | +| Styling | ✓ | ✓ | ✓ | ✓ | |
| 40 | +| React.array | | | ✓ | | |
19 | 41 |
|
20 | | -Note that any hot reload on a route will fall back to the root (`/`), so `ReasonReact.Router.dangerouslyGetInitialUrl` will likely be needed alongside the `ReasonReact.Router.watchUrl` logic to handle routing correctly on hot reload refreshes or simply opening the app at a URL that is not the root. |
| 42 | +# Bundle for Production |
21 | 43 |
|
22 | | -To use a port other than 8000 set the `PORT` environment variable (`PORT=8080 npm run server`). |
| 44 | +We've included a convenience `UNUSED_webpack.config.js`, in case you want to ship your project to production. You can rename and/or remove that in favor of other bundlers, e.g. Rollup. |
23 | 45 |
|
24 | | -## Build for Production |
| 46 | +We've also provided a barebone `indexProduction.html`, to serve your bundle. |
25 | 47 |
|
26 | 48 | ```sh |
27 | | -npm run clean |
28 | | -npm run build |
29 | | -npm run webpack:production |
| 49 | +npm install webpack webpack-cli |
| 50 | +# rename file |
| 51 | +mv UNUSED_webpack.config.js webpack.config.js |
| 52 | +# call webpack to bundle for production |
| 53 | +./node_modules/.bin/webpack |
| 54 | +open indexProduction.html |
30 | 55 | ``` |
31 | | - |
32 | | -This will replace the development artifact `build/Index.js` for an optimized version as well as copy `src/index.html` into `build/`. You can then deploy the contents of the `build` directory (`index.html` and `Index.js`). |
33 | | - |
34 | | -If you make use of routing (via `ReasonReact.Router` or similar logic) ensure that server-side routing handles your routes or that 404's are directed back to `index.html` (which is how the dev server is set up). |
35 | | - |
36 | | -**To enable dead code elimination**, change `bsconfig.json`'s `package-specs` `module` from `"commonjs"` to `"es6"`. Then re-run the above 2 commands. This will allow Webpack to remove unused code. |
|
0 commit comments