Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Modern workflow (esbuild, Storybook) #12

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

domq
Copy link
Member

@domq domq commented Dec 7, 2023

  • Remove dependency on create-react-app tooling (unmaintained for 2 years); replace with esbuild
  • Add storybook so as to be able to develop widgets without a functioning back-end (or front-end)
  • As the latter doesn't quite support esbuild yet, use Vite just for the storybook.

@domq domq requested a review from rosamaggi December 7, 2023 10:09
@domq domq force-pushed the feature/storybook branch 6 times, most recently from 994b1e6 to 57dcfb4 Compare December 7, 2023 14:09
@domq
Copy link
Member Author

domq commented Dec 7, 2023

Still to-do: resolve the following Yarn warning.

@types/react is listed by your project with version 18.2.42, which doesn't satisfy what @material-ui/core (p88ab7) and other dependencies request (^16.8.6 || ^17.0.0).

@rosamaggi rosamaggi marked this pull request as draft December 7, 2023 15:29
Dominique Quatravaux and others added 20 commits December 7, 2023 17:02
```
yarn remove @epfl/epfl-sti-react-library
```
This is an actual dependency of our code, but previously we were getting away with not declaring it because `@epfl/epfl-sti-react-library` also used to require it.
- I don't have a `packages/` subdirectory (nor do I want one)
- Apply https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
```
yarn add -D esbuild esbuild-plugin-inline-image
```
- Write a `esbuild.mjs` script to build all the things under `dist/`
- Embed a reverse proxy in there, as advised [in the esbuild documentation](https://esbuild.github.io/api/#serve-proxy). Its job is to serve `public/index.html` except on select URIs (the ones we know that esbuild can handle by itself)
- Support development and production builds
- Trim all the create-react-app-ey bells and whistles out of `public/index.html`
- Load the JS explicitly as part of a `<script defer>` in same `public/index.html` (this used to be done implicitly with `create-react-app`)
- Add `/dist/` to `.gitignore`
💡 That package is dead (last release in 2021).

```bash
yarn remove react-scripts
```
Before: we had to do it the `create-react-script` way as per https://create-react-app.dev/docs/adding-custom-environment-variables/

After: use [esbuild's `define:` feature](https://esbuild.github.io/api/#define).

- Fold all the fallback values business into JavaScript (i.e. no `.env` files anymore)
- Switch between development and production values according to `window.IS_PRODUCTION` (which won't actually be set, just substituted by esbuild at build time).
As per https://esbuild.github.io/api/#live-reload :

- `.serve()` and `.watch()` both
- Whitelist `/esbuild` to go through the reverse proxy
- `src/index.js`: listen to the `/esbuild` event, for development builds only
```
yarn add epfl-elements
```
- Teach esbuild what it means to import CSS (i.e. add a suitable `loader`)
- Do import the CSS from the JS (which causes esbuild to build the CSS as per https://esbuild.github.io/content-types/#css-from-js)
- Whitelist `lhd3-frontend.css` in the reverse proxy
- Call the CSS from the HTML homepage
... and eslint something-something.

Despite the [hype](https://storybook.js.org/docs/builders/builder-api), Storybook doesn't [currently](storybookjs/storybook#24614) support esbuild. So we need a new build system just for it 🤷.

```
yarn add -D vite
npx storybook@latest init -b vite -y
```
The idea is to be able to run both this one and the one from https://github.com/epfl-si/epfl-elements-react at once.
```
yarn remove @storybook/addon-onboarding
```
```
yarn add epfl-elements
```
```
yarn set version latest
yarn
```
Problem 1: `@storybook/builder-vite@npm:7.6.3` requires `@vitejs/plugin-react": "^3.0.1`, which is [ancient](https://www.npmjs.com/package/@vitejs/plugin-react?activeTab=versions) and doesn't go with Vite 5.

Problem 2: we do not want to downgrade to Vite 4.

While [in may be only a matter of days or weeks](storybookjs/storybook#24953) until the situation changes, the [currently recommended workaround](storybookjs/storybook#24901) is to cheat on the version of the latter, given that according to the comment cited, it is dead code anyway as long as we have a top-level Vite configuration (which we do).
Dominique Quatravaux and others added 5 commits December 7, 2023 17:15
```
yarn remove @react-keycloak/web
yarn add @mui/base @mui/system @popperjs/core
yarn add -D @testing-library/dom
```
We shall change this when the first version of `epfl-elements-react` is released.
... As suggested by the previous commit.

Since we currently don't have a released version of `epfl-elements-react`; but that on the other hand, the [LHDv3 dev kit](https://github.com/epfl-si/lhd3-dev) ensures that `../epfl-elements-react` is available; it just feels better to commit this for now (even if we might incur some commit noise due to checksums changing back and forth between workspaces of team members).
These were for React 18, while React is currently installed with version 17.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants