Skip to content

Commit

Permalink
Use Vite instead of CRA (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaiTon authored Jul 9, 2023
1 parent b9d4f93 commit 9160cc5
Show file tree
Hide file tree
Showing 18 changed files with 646 additions and 7,225 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ yarn-debug.log*
yarn-error.log*

.idea

# vite build
dist/
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ The main goal is: Every Open Food Facts user can annotate products in a few minu

## Setup:

- Install Node: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
- Install yarn `npm install --global yarn`
- Install libraries `yarn install`
- run the project locally `yarn start` (available on http://localhost:3000)
- [Install Node](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
- [Install yarn](https://classic.yarnpkg.com/lang/en/docs/install/)
- Install libraries: `yarn install`
- run the project locally `yarn dev`

## Libraries:

Expand All @@ -54,19 +54,23 @@ Open Food Facts APIs and [Robotoff](https://github.com/openfoodfacts/robotoff)

## Build

- `yarn build`

Use a [simple webpack config](https://github.com/facebook/create-react-app/issues/3365#issuecomment-376546407) to bundle in a single file (build/bundle.min.js) and facilitate integration in OFF main site
```
yarn build
```

## Countries list

- `yarn countries`
```
yarn countries
```

Generate the JSON file `src/assets/countries.json` which contains all the countries available on OFF taxonomy. Data are obtained from static.openfoodfacts.org

## Taxonomy auto-complete

- `node update-taxonomy-suggestions.js`
```
node update-taxonomy-suggestions.js
```

Fetch categories and labels taxonomy from OpenFoodFacts static files, and generate JSON files used by the `Autocomplete` fields.

Expand Down
48 changes: 48 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Answer questions, make food transparency happen"
/>
<link rel="apple-touch-icon" href="/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="/manifest.json" />

<title>Hunger Games</title>
<meta name="viewport" content="initial-scale=1, width=device-width" />
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<script>
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker
.register("/serviceWorker.js")
.then((reg) => console.log("Success: ", reg.scope))
.catch((err) => console.log("Failure: ", err));
});
}
</script>
<script src="/src/index.tsx" type="module"></script>
</body>
</html>
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,20 @@
"devDependencies": {
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.6",
"babel-loader": "^8.2.5",
"@vitejs/plugin-react": "^4.0.2",
"husky": "^8.0.2",
"prettier": "2.8.7",
"pretty-quick": "^3.1.3",
"react-scripts-ts": "^3.1.0",
"typescript": "^4.9.5",
"webpack-cli": "^5.0.1"
"vite": "^4.4.2"
},
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"prettier": "prettier --write .",
"start": "react-scripts start",
"countries": "node update-countries.js",
"build": "npm run build:react && npm run build:bundle",
"build:react": "react-scripts build",
"build:bundle": "webpack --config webpack.config.js",
"test": "react-scripts test",
"eject": "react-scripts eject",
"deploy": "bash deploy.sh",
"prepare": "husky install"
},
Expand Down
51 changes: 0 additions & 51 deletions public/index.html

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions src/components/Footer/DiscoverTheProject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const DiscoverTheProject = () => {
{discover.map((content) => {
return (
<Button
key={content.text}
sx={{
backgroundColor: "#a08d84",
"&:hover": { backgroundColor: "#887369" },
Expand Down
2 changes: 1 addition & 1 deletion src/components/Footer/Donate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Donate = () => {
{t("settings.text1")}
<br />
<br />
<Typography variant="h6">{t("settings.thank_you")} ❤️</Typography>
{t("settings.thank_you")} ❤️
</Typography>
</Box>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/Footer/DownloadOpenFoodFacts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const DownloadOpenFoodFacts = () => {
{footerLinks.map((link) => {
return (
<FooterButtons
key={link.title}
title={link.title}
subTitle={link.subTitle}
icon={link.icon}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Footer/OpenFoodFacts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const OpenFoodFacts = () => {
<Box>
{socialMedia.map((media) => {
return (
<IconButton href={media.link} target="_blank">
<IconButton key={media.link} href={media.link} target="_blank">
{media.icon}
</IconButton>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/QuestionFilter/LabelFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { URL_ORIGINE } from "../../const";
// Otherwise fallback on english
const AVAILABLE_OPTIONS = ["de", "es", "fr", "hr", "nl", "sv"];

const cleanName = (name) =>
const cleanName = (name: string) =>
name
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
Expand Down
3 changes: 2 additions & 1 deletion src/components/welcome/Welcome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Typography from "@mui/material/Typography";
import { useTheme } from "@mui/material/styles";
import useControlled from "@mui/utils/useControlled";
import useMediaQuery from "@mui/material/useMediaQuery";
import logo from "../../assets/logo.png";

import Tour from "reactour";
import {
Expand Down Expand Up @@ -37,7 +38,7 @@ export const getSteps = ({ t, withSelector, theme }) => [
height: "auto",
flex: "20%",
}}
src={require("../../assets/logo.png")}
src={logo}
/>
<Typography
variant="h6"
Expand Down
2 changes: 1 addition & 1 deletion src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const OFF_IMAGE_URL = "https://static.openfoodfacts.org/images/products";
export const OFF_SEARCH = "https://world.openfoodfacts.org/cgi/search.pl";
export const IS_DEVELOPMENT_MODE = process.env.NODE_ENV === "development";
export const URL_ORIGINE = IS_DEVELOPMENT_MODE
? "http://localhost:3000"
? "http://localhost:5173"
: "https://hunger.openfoodfacts.org/";
export const NO_QUESTION_LEFT = "NO_QUESTION_LEFT";

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
plugins: [react()],
});
35 changes: 0 additions & 35 deletions webpack.config.js

This file was deleted.

Loading

0 comments on commit 9160cc5

Please sign in to comment.