Skip to content

Commit

Permalink
Feature/vite (#19)
Browse files Browse the repository at this point in the history
* refactor using vite

* eslint

* fix docker

* add background color before initialisation
  • Loading branch information
danieleguido authored Aug 28, 2023
1 parent 9495099 commit 2f4b5d7
Show file tree
Hide file tree
Showing 97 changed files with 2,233 additions and 6,880 deletions.
18 changes: 9 additions & 9 deletions .env
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
REACT_APP_PROXY=http://localhost
REACT_APP_LANGUAGES=en-GB,fr-FR,de-DE
REACT_APP_EMAIL=[email protected]
REACT_APP_ORIGIN=https://memorialshoah.lu
REACT_APP_MAPBOX_ACCESS_TOKEN=pk.eyJ1IjoiZGFuaWVsZWd1aWRvdW5pIiwiYSI6ImNpcm5odTNjbTAwNWdoc2t3bnM5OTl4cnAifQ.4-Ai1NwYuDLEUPRBnDoG7g
REACT_APP_MAPBOX_STYLE_URL=mapbox://styles/danieleguidouni/cl91d7hxh002g14qob4sbp5fr
REACT_APP_LOCALSTORAGE_NAME=memorialshoah
REACT_APP_MATOMO_URLBASE=https://journalofdigitalhistory.matomo.cloud/
REACT_APP_MATOMO_SITEID=2
VITE_PROXY=http://localhost
VITE_LANGUAGES=en-GB,fr-FR,de-DE
VITE_EMAIL=[email protected]
VITE_ORIGIN=https://memorialshoah.lu
VITE_MAPBOX_ACCESS_TOKEN=pk.eyJ1IjoiZGFuaWVsZWd1aWRvdW5pIiwiYSI6ImNpcm5odTNjbTAwNWdoc2t3bnM5OTl4cnAifQ.4-Ai1NwYuDLEUPRBnDoG7g
VITE_MAPBOX_STYLE_URL=mapbox://styles/danieleguidouni/cl91d7hxh002g14qob4sbp5fr
VITE_LOCALSTORAGE_NAME=memorialshoah
VITE_MATOMO_URLBASE=https://journalofdigitalhistory.matomo.cloud/
VITE_MATOMO_SITEID=2
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["react-app"]
}
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ RUN yarn install

COPY public ./public
COPY src ./src
COPY vite.config.js .
COPY index.html .
COPY .env .

ENV NODE_ENV production
ENV NODE_OPTIONS --max_old_space_size=4096

ENV REACT_APP_GIT_TAG=${GIT_TAG}
ENV REACT_APP_GIT_BRANCH=${GIT_BRANCH}
ENV REACT_APP_GIT_REVISION=${GIT_REVISION}
ENV VITE_GIT_TAG=${GIT_TAG}
ENV VITE_GIT_BRANCH=${GIT_BRANCH}
ENV VITE_GIT_REVISION=${GIT_REVISION}

RUN yarn run build

Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
BUILD_TAG ?= latest

run-dev:
REACT_APP_GIT_TAG=$(shell git describe --tags --abbrev=0 HEAD) \
REACT_APP_GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) \
REACT_APP_GIT_REVISION=$(shell git rev-parse --short HEAD) \
VITE_GIT_TAG=$(shell git describe --tags --abbrev=0 HEAD) \
VITE_GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) \
VITE_GIT_REVISION=$(shell git rev-parse --short HEAD) \
yarn start

build-docker-image:
Expand All @@ -13,8 +13,8 @@ build-docker-image:
--build-arg GIT_REVISION=$(shell git rev-parse --short HEAD) .

run-deploy-netlify:
REACT_APP_GIT_TAG=$(shell git describe --tags --abbrev=0 HEAD) \
REACT_APP_GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) \
REACT_APP_GIT_REVISION=$(shell git rev-parse --short HEAD) \
VITE_GIT_TAG=$(shell git describe --tags --abbrev=0 HEAD) \
VITE_GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) \
VITE_GIT_REVISION=$(shell git rev-parse --short HEAD) \
yarn build && \
netlify deploy --prod --dir=build
35 changes: 35 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!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="Memorial Shoah" />
<link rel="apple-touch-icon" href="/logo192.png" />
<meta data-react-helmet="true" property="og:image" content="/screen.png" />
<meta property="og:title" content="Memorial Shoah" data-react-helmet="true" />
<meta
name="description"
content="The Digital Shoah Memorial in Luxembourg is built in memory of people who lived in Luxembourg, who were persecuted, who were victims of Nazi anti-Semitic legislation during World War II."
data-react-helmet="true"
/>
<meta
property="og:description"
content="The Digital Shoah Memorial in Luxembourg is built in memory of people who lived in Luxembourg, who were persecuted, who were victims of Nazi anti-Semitic legislation during World War II."
data-react-helmet="true"
/>
<link rel="manifest" href="/manifest.json" />
<title>Memorial Shoah</title>
<style>
body {
background-color: #ffefe5;
}
</style>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/index.jsx"></script>
</body>
</html>
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
"@testing-library/user-event": "^13.5.0",
"@u-wave/react-vimeo": "^0.9.8",
"@use-gesture/react": "^10.2.20",
"@vitejs/plugin-react": "^4.0.4",
"axios": "^0.27.2",
"bootstrap": "^5.2.0-beta1",
"citation-js": "^0.6.4",
"d3-array": "^3.1.6",
"downsize": "^0.0.8",
"eslint": "^8.48.0",
"eslint-config-react-app": "^7.0.1",
"i": "^0.3.7",
"i18next": "^21.8.8",
"leva": "^0.9.31",
Expand All @@ -40,23 +43,23 @@
"react-markdown": "^8.0.3",
"react-query": "^3.39.1",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"react-spring": "^9.4.5",
"remark-footnotes": "^4.0.1",
"remark-gfm": "^3.0.1",
"simplex-noise": "^3.0.1",
"three": "^0.145.0",
"three.modifiers": "^2.5.7",
"use-query-params": "^1.2.3",
"vite": "^4.4.9",
"vite-plugin-eslint": "^1.8.1",
"web-vitals": "^2.1.4",
"worker-loader": "^3.0.8",
"zustand": "^4.0.0-rc.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"start": "vite",
"build": "vite build",
"serve": "vite preview",
"lint": "eslint -c .eslintrc.js --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "npm run lint -- --fix"
},
Expand All @@ -79,7 +82,6 @@
]
},
"devDependencies": {
"eslint": "^8.17.0",
"http-proxy-middleware": "^2.0.6",
"prettier": "^2.7.1"
}
Expand Down
52 changes: 0 additions & 52 deletions public/index.html

This file was deleted.

10 changes: 1 addition & 9 deletions src/App.js → src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ console.info('initial languageCode', languageCode)
const Biographies = lazy(() => import('./pages/Biographies'))
const Document = lazy(() => import('./pages/Document'))
const Home = lazy(() => import('./pages/Home'))
const Lines = lazy(() => import('./pages/Lines'))
const NotFound = lazy(() => import('./pages/NotFound'))
const Page = lazy(() => import('./pages/Page'))
const Person = lazy(() => import('./pages/Person'))
Expand Down Expand Up @@ -68,14 +67,7 @@ const App = () => {
</React.Suspense>
}
/>
<Route
path="lines"
element={
<React.Suspense fallback={<>...</>}>
<Lines isMobile={isMobile} />
</React.Suspense>
}
></Route>

<Route
path="people"
element={
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/components/Cookies.js → src/components/Cookies.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, Form, Container } from 'react-bootstrap'
import { usePermanentStore } from '../store'
import { TermsOfUseRoute } from '../constants'
import LangLink from './LangLink'
import styles from '../styles/components/Cookie.css'
import '../styles/components/Cookie.css'
import { useTimeout } from '../hooks/timeout'

const Cookies = ({ defaultAcceptCookies }) => {
Expand Down Expand Up @@ -66,13 +66,13 @@ const Cookies = ({ defaultAcceptCookies }) => {
onChange={handleChange}
/>
</Form>
<p className={styles.agreement}>
<p className="Cookies__agreement">
By browsing this website you agree to our cookie policy. Visit{' '}
<LangLink to={TermsOfUseRoute.to}>{t(TermsOfUseRoute.label)}</LangLink> to review your
options later.
</p>
<div className="mx-3 my-0 my-md-3">
<Button className={styles.AgreeButton} onClick={handleClickAgree}>
<Button className="Cookies__agreeButton" onClick={handleClickAgree}>
Agree
</Button>
</div>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'

const GetInTouch = ({ emailSubjectTranslationLabel = 'getInTouchSubject' }) => {
const { t } = useTranslation()
const href = `mailto:${process.env.REACT_APP_EMAIL}?subject=${encodeURIComponent(
const href = `mailto:${import.meta.env.VITE_EMAIL}?subject=${encodeURIComponent(
t(emailSubjectTranslationLabel),
)}`

Expand Down
12 changes: 2 additions & 10 deletions src/components/Header.js → src/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import Logo from './Logo'
import {
BootstrapStartColumnLayoutNoOffset,
BootstrapEndColumnLayout,
DefaultLanguageCode,
LanguageCodes,
LanguagePathRegExp,
LanguageRootPathRegExp,
AboutRoute,
StoryRoute,
Expand All @@ -25,13 +22,8 @@ const Header = () => {
const { t } = useTranslation()
const routeLabel = useStore((state) => state.routeLabel)

const activeLanguage = window.location.pathname.match(LanguagePathRegExp)
// const activeLanguage = window.location.pathname.match(LanguagePathRegExp)
const isRootPath = window.location.pathname.match(LanguageRootPathRegExp)
const activeLanguageCode = activeLanguage
? activeLanguage[1]
: isRootPath
? isRootPath[1]
: DefaultLanguageCode

return (
<header className="Header">
Expand Down Expand Up @@ -116,7 +108,7 @@ const Header = () => {
</li>

<li>
<LanguageSwitch className="d-flex" linkClassName="ms-3" />
<LanguageSwitch isRootPath={isRootPath} className="d-flex" linkClassName="ms-3" />
</li>
</ul>
</nav>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const HomeBiographies = ({ isMobile, speed, availableWidth, availableHeight, cla
empty
</li>
{status === StatusSuccess
? data.results.map((story) => (
? data.results?.map((story) => (
<li
key={story.slug}
className={`HomeBiographies_storyListItem ${
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions src/components/LinesMap.js → src/components/LinesMap.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import ReactMapboxGl, { MapContext, ZoomControl, Cluster, Marker } from 'react-mapbox-gl'
import mapboxgl from 'mapbox-gl'
import MapboxWorker from 'worker-loader!mapbox-gl/dist/mapbox-gl-csp-worker' // eslint-disable-line import/no-webpack-loader-syntax
// eslint-disable-next-line import/no-webpack-loader-syntax
import MapboxWorker from 'mapbox-gl/dist/mapbox-gl-csp-worker' // eslint-disable-line import/no-webpack-loader-syntax
import '../styles/components/LinesMap.css'
import LinesMapLineLayer from './LinesMapLineLayer'

import 'mapbox-gl/dist/mapbox-gl.css'

const Map = ReactMapboxGl({
accessToken: process.env.REACT_APP_MAPBOX_ACCESS_TOKEN,
accessToken: import.meta.env.VITE_MAPBOX_ACCESS_TOKEN,
projection: 'naturalEarth',
})

Expand Down Expand Up @@ -103,7 +104,7 @@ const LinesMap = ({
return (
<div className={`LinesMap ${className}`} style={{ width, height, overflow: 'hidden' }}>
<Map
style={`${process.env.REACT_APP_MAPBOX_STYLE_URL}?optimize=true`}
style={`${import.meta.env.VITE_MAPBOX_STYLE_URL}?optimize=true`}
className="map h-100 w-100"
center={center}
zoom={[zoom]}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const StoryHelmet = ({ story, language }) => {
description = story.contents.modules[0].text.content[language]
cover =
story.covers.length > 0
? String(process.env.REACT_APP_ORIGIN + story.covers[0].data?.resolutions?.medium?.url)
? String(import.meta.env.VITE_ORIGIN + story.covers[0].data?.resolutions?.medium?.url)
: '/screen.png'
} catch (error) {
console.warn('[Storyhelmet] error in rendering, skipping. ', error)
Expand Down Expand Up @@ -66,7 +66,7 @@ const StoryHelmet = ({ story, language }) => {
<meta name="dc:title" content={title} />
<meta name="dc:publisher" content="C2DH - University of Luxembourg" />
<meta property="og:site_name" content="memorialshoah.lu" />
<meta property="og:url" content={process.env.REACT_APP_ORIGIN + window.location.pathname} />
<meta property="og:url" content={import.meta.env.VITE_ORIGIN + window.location.pathname} />
<meta property="og:title" content={title} />
<meta name="twitter:site" content="@memorialshoahlu" />
<meta name="twitter:card" content="summary" />
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const ModuleTextAnchor = ({ node, children, href, ...props }) => {
)
}
// check if href is the website one (internal links)
if (href.indexOf(process.env.REACT_APP_ORIGIN) !== -1) {
if (href.indexOf(import.meta.env.VITE_ORIGIN) !== -1) {
// remove origin, e.g. `https://` and language `/en/` from the href to make page specific
const to = href.replace(process.env.REACT_APP_ORIGIN, '').replace(LanguagePathRegExp, '')
const to = href.replace(import.meta.env.VITE_ORIGIN, '').replace(LanguagePathRegExp, '')
return (
<LangLink className="ModuleTextAnchor" to={to} {...props}>
{textNode}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ export const AllRoutes = [
LinesMapRoute,
]

export const Languages = (process.env.REACT_APP_LANGUAGES ?? 'en-GB,fr-FR,de-DE').split(',')
export const Languages = (import.meta.env.VITE_LANGUAGES ?? 'en-GB,fr-FR,de-DE').split(',')
export const MillerLanguages = Languages.map((l) => l.split('-').join('_'))
export const LanguageCodes = Languages.map((l) => l.split('-')[0])
export const LanguageRoutePattern = `/:lang(${LanguageCodes.join('|')})`
export const LanguagePathRegExp = new RegExp(`/(${LanguageCodes.join('|')})/`)
export const LanguageRootPathRegExp = new RegExp(`^/(${LanguageCodes.join('|')})/?$`)
export const DefaultLanguage = process.env.REACT_APP_DEFAULT_LANGUAGE ?? 'en-GB'
export const DefaultLanguage = import.meta.env.VITE_DEFAULT_LANGUAGE ?? 'en-GB'
export const DefaultLanguageCode = DefaultLanguage.split('-')[0]

export const MillerAPI = process.env.REACT_APP_MILLER_API ?? '/api'
export const MillerAPI = import.meta.env.VITE_MILLER_API ?? '/api'

export const BootstrapColumnLayout = Object.freeze({
md: { span: 11, offset: 1 },
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const useGetJSON = ({
url,
memoid = '',
delay = 0,
timeout = process.env.REACT_APP_API_TIMEOUT || 0,
timeout = import.meta.env.VITE_API_TIMEOUT || 0,
onDownloadProgress,
params,
}) => {
Expand Down
Loading

0 comments on commit 2f4b5d7

Please sign in to comment.