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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
945ba4d
[feature] Homemade implementation of `<Logo>`
Dec 4, 2023
64d3d76
[undepends] `@epfl/epfl-sti-react-library`
Dec 4, 2023
19c974c
[depends] `dayjs`
Dec 4, 2023
a685972
[cleanup] Update `.gitignore`
Dec 5, 2023
05abed0
[depends] `esbuild`, `esbuild-plugin-inline-image`
Dec 4, 2023
d453b33
[feature] Bye `create-react-app`, welcome esbuild
domq Dec 4, 2023
a8101b9
[undepends] `react-scripts`
Nov 28, 2023
7a3b7b0
[refactor]&[fix] 12-factor business
Dec 4, 2023
067d677
[feature] Live (hot) reload
Dec 4, 2023
a2c85ae
[document] the new development workflow
Dec 4, 2023
f2b249e
[depends] `epfl-elements`
Dec 4, 2023
112e6ae
[feature] Embed epfl-elements CSS (explicitly)
Dec 5, 2023
bfbda7e
[install] Storybook (and Vite)
Dec 5, 2023
024867e
[fix] Change Storybook port
Dec 7, 2023
1fdc52c
[document] the life of `dist/lhd3-frontend.css` in a comment
Dec 7, 2023
698aabe
[unfeature] We don't need `yarn build-storybook`
Dec 7, 2023
fcda5d0
[unscaffold] `@storybook/addon-onboarding`
Dec 7, 2023
cb5a64b
[upgrade] `epfl-elements`
Dec 7, 2023
f5a692f
[upgrade] to yarn “berry”
Dec 7, 2023
972edd0
[workaround] Yarn whining about Vite 5 being too new
Dec 7, 2023
b3f5a4d
[fix] (most) Yarn dependency whines
Dec 7, 2023
2ef7e21
[document] Learn test for cross-project joint development
Dec 7, 2023
293be6d
[scaffold] `yarn add epfl-elements-react@file:../epfl-elements-react`
Dec 7, 2023
970cf6a
[Feature] Add Dispensation stories
rosamaggi Dec 7, 2023
9b8005d
[fix] Mismatched `@types/react` and `@types/react-dom` versions
Dec 7, 2023
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
8 changes: 0 additions & 8 deletions .env.development

This file was deleted.

7 changes: 0 additions & 7 deletions .env.production

This file was deleted.

22 changes: 10 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ chrome-user-data
*.swp
*.swo

packages/react-devtools-core/dist
packages/react-devtools-extensions/chrome/build
packages/react-devtools-extensions/chrome/*.crx
packages/react-devtools-extensions/chrome/*.pem
packages/react-devtools-extensions/firefox/build
packages/react-devtools-extensions/firefox/*.xpi
packages/react-devtools-extensions/firefox/*.pem
packages/react-devtools-extensions/shared/build
packages/react-devtools-extensions/.tempUserDataDir
packages/react-devtools-inline/dist
packages/react-devtools-shell/dist
packages/react-devtools-scheduling-profiler/dist
.env
/dist/

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

/test-results/
/playwright-report/
/playwright/.cache/
18 changes: 18 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-vite",
options: {},
},
docs: {
autodocs: "tag",
},
};
export default config;
15 changes: 15 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Preview } from "@storybook/react";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
compressionLevel: mixed

enableGlobalCache: false

nodeLinker: node-modules

npmScopes:
epfl:
npmRegistryServer: https://sti-nodejs.epfl.ch/
npmRegistryServer: "https://sti-nodejs.epfl.ch/"

yarnPath: .yarn/releases/yarn-4.0.2.cjs
72 changes: 4 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,6 @@
# Getting Started with Create React App
# LHD v3: Frontend

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

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

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

### `yarn test`

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.

### `yarn 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.

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

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](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](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](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](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](https://facebook.github.io/create-react-app/docs/deployment)

### `yarn build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
1. Run `yarn start`
2. Browse http://localhost:3000/ as directed
94 changes: 94 additions & 0 deletions esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import * as esbuild from 'esbuild';
import * as process from 'node:process';
import inlineImage from 'esbuild-plugin-inline-image';
import http from 'node:http';
import { readFile } from 'node:fs/promises';

const cmd = process.argv[process.argv.length - 1];

function usage() {
console.log(`Usage: esbuild.mjs build | dev`);
process.exit(1);
}

const commonBuildConfig = {
entryPoints: ['src/index.js'],
bundle: true,
loader: {
".js": "jsx",
".css": "global-css",
},
outfile: 'dist/lhd3-frontend.js', // and implicitly,
// dist/lhd3-frontend.css for all
// the css
plugins: [inlineImage()],
};

if (cmd === "build") {
catchy(() => esbuild.build({
color: true,
logLevel: 'info',
minify: true,
define: {
"window.IS_PRODUCTION": `true`
},
...commonBuildConfig
}));
} else if (cmd === "dev") {
catchy(devServer);
} else {
usage();
}

async function catchy (continuation) {
try {
await continuation();
} catch (e) {
console.error(e);
process.exit(2);
}
}

async function devServer () {
const ctx = await esbuild.context({
define: {
"window.IS_PRODUCTION": `false`
},
...commonBuildConfig
});

// https://esbuild.github.io/api/#live-reload
await ctx.watch();

// https://esbuild.github.io/api/#serve-proxy
let server = await ctx.serve();

function doProxy(req, res) {
const options = {
hostname: server.host,
port: server.port,
path: req.url,
method: req.method,
headers: req.headers,
}
const proxyReq = http.request(options, proxyRes => {
res.writeHead(proxyRes.statusCode, proxyRes.headers)
proxyRes.pipe(res, { end: true })
});
req.pipe(proxyReq, { end: true });
}

await http.createServer(async (req, res) => {
if (req.url.endsWith('/lhd3-frontend.js') ||
req.url.endsWith('/lhd3-frontend.css') ||
req.url.endsWith('/esbuild')) {
doProxy(req, res);
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(await readFile('public/index.html'));
}
}).listen(3000);

console.log("🚀 Browse the LHD frontend at http://localhost:3000/");
console.log("\n🔥 Hot reload is enabled!");
}
42 changes: 32 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,43 @@
"@emotion/react": "^11.5.0",
"@emotion/styled": "^11.3.0",
"@epfl-si/react-appauth": "^0.9.0",
"@epfl/epfl-sti-react-library": "^2.4.0",
"@material-ui/core": "^4.12.3",
"@mui/base": "^5.0.0-beta.26",
"@mui/icons-material": "^5.1.0",
"@mui/joy": "^5.0.0-alpha.80",
"@mui/material": "^5.0.6",
"@mui/system": "^5.14.20",
"@mui/x-data-grid": "5.0.0-beta.5",
"@mui/x-date-pickers": "^6.4.0",
"@react-keycloak/web": "^3.4.0",
"@popperjs/core": "^2.11.8",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"bootstrap": "^5.1.3",
"caniuse-lite": "^1.0.30001304",
"dayjs": "^1.11.10",
"epfl-elements": "^4.6.1",
"epfl-elements-react": "file:../epfl-elements-react",
"i18next": "^22.0.3",
"react": "^17.0.2",
"react-bootstrap": "^2.0.0",
"react-dom": "^17.0.2",
"react-hook-form": "^7.43.9",
"react-i18next": "^12.0.0",
"react-router-dom": "^5.3.3",
"react-scripts": "^5.0.1",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "GENERATE_SOURCEMAP=false react-scripts start",
"build": "react-scripts build",
"start": "node esbuild.mjs dev",
"build": "node esbuild.mjs build",
"test": "mocha --reporter-option diffSize=5000",
"eject": "react-scripts eject"
"storybook": "storybook dev -p 6008"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
"react-app/jest",
"plugin:storybook/recommended"
]
},
"browserslist": {
Expand All @@ -55,15 +59,33 @@
},
"devDependencies": {
"@playwright/test": "^1.38.1",
"@storybook/addon-essentials": "^7.6.3",
"@storybook/addon-interactions": "^7.6.3",
"@storybook/addon-links": "^7.6.3",
"@storybook/blocks": "^7.6.3",
"@storybook/react": "^7.6.3",
"@storybook/react-vite": "^7.6.3",
"@storybook/test": "^7.6.3",
"@testing-library/dom": "^9.3.3",
"@types/mocha": "^10.0.0",
"@types/node": "^20.7.0",
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-router-dom": "^5.3.3",
"chai": "^4.3.6",
"esbuild": "^0.19.8",
"esbuild-plugin-inline-image": "^0.0.9",
"eslint": "^8.38.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-storybook": "^0.6.15",
"mocha": "^10.1.0",
"typescript": "^5.0.4"
"storybook": "^7.6.3",
"typescript": "^5.0.4",
"vite": "^5.0.5"
},
"packageManager": "[email protected]",
"resolutions": {
"@vitejs/plugin-react": "^4.2.1",
"__explanations__": "can be had with `git blame`. Once https://github.com/storybookjs/storybook/pull/24953 is merged and released, upgrade `@storybook/react-vite` devDependency, and delete this whole `resolutions` section (or un-rebase the commit that added it)"
}
}
17 changes: 0 additions & 17 deletions public/favicon.svg

This file was deleted.

Loading