refactor: use vite instead of CRA

This commit is contained in:
2026-04-04 14:57:32 +02:00
parent 02872f61ce
commit 408adf4b4d
16 changed files with 1005 additions and 9367 deletions
+3 -4
View File
@@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js 18.x
- name: Setup Node.js 24.x
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 24.x
- name: Cache NPM packages
uses: actions/cache@v4
with:
@@ -27,11 +27,10 @@ jobs:
- name: Yarn Install
run: |
cd ./frontend
yarn install --frozen-lockfiles
yarn install
- name: Yarn Test
run: |
cd ./frontend
./compile-less.sh
yarn run test
docker-fe-build:
+2 -1
View File
@@ -30,4 +30,5 @@ yarn-error.log*
/local
obj/
bin/
bin/
dist/
+2 -2
View File
@@ -1,2 +1,2 @@
nodejs 20.15.1
yarn 1.22.22
nodejs 24.14.1
yarn 1.22.22
+4 -5
View File
@@ -1,17 +1,16 @@
FROM node:20.15.1-bookworm as builder
FROM node:24.14.1-trixie AS builder
WORKDIR "/src"
COPY ["package.json", "yarn.lock", "./"]
RUN yarn install --frozen-lockfile
RUN yarn install
COPY . .
RUN ./compile-less.sh
RUN yarn build
FROM nginx:latest as proxy
FROM nginx:1.29.7-alpine3.23 AS proxy
COPY --from=builder "/src/build" "/usr/share/nginx/html"
COPY --from=builder "/src/dist" "/usr/share/nginx/html"
COPY ./nginx.conf /etc/nginx/nginx.conf
+12 -41
View File
@@ -1,46 +1,17 @@
# Getting Started with Create React App
# Frontend (Vite)
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This frontend now uses Vite + React + TypeScript.
## Available Scripts
## Scripts
In the project directory, you can run:
- `yarn dev` or `yarn start`: Start the Vite dev server.
- `yarn build`: Build production assets to `dist/`.
- `yarn preview`: Serve the production build locally.
- `yarn test`: Run tests once with Vitest.
- `yarn test:watch`: Run tests in watch mode.
### `yarn start`
## Notes
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 run 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 run eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent 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 youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt 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/).
- Static files are served from `public/`.
- The app entry HTML is `index.html` at the project root.
- LESS files are compiled by Vite automatically, no separate compile step is needed.
-13
View File
@@ -1,13 +0,0 @@
#!/bin/bash
echo "Compiling all LESS files to CSS"
function compile_less() {
FROM=$1
TO=${FROM/.*/.css}
SOURCE_MAP=${FROM/.*/.css.map}
echo "$FROM --> $TO & $SOURCE_MAP"
node_modules/less/bin/lessc "$FROM" "$TO" --source-map="$SOURCE_MAP"
}
export -f compile_less
find src -type f -name '*.less' -exec bash -c 'compile_less $1' shell {} \;
+21
View File
@@ -0,0 +1,21 @@
<!doctype html>
<html lang="hu">
<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="Kém Karakter alkotási segédlet" />
<link rel="apple-touch-icon" href="/logo192.png" />
<link rel="manifest" href="/manifest.json" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Merienda&display=swap" rel="stylesheet" />
<title>Kém Karakter App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
+14 -25
View File
@@ -2,6 +2,9 @@
"name": "kemkas",
"version": "0.1.0",
"private": true,
"engines": {
"node": ">=24"
},
"dependencies": {
"@grafana/faro-web-sdk": "^1.4.2",
"@pdf-lib/fontkit": "^1.1.1",
@@ -9,25 +12,19 @@
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.1",
"@types/jest": "^29.5.6",
"@types/node": "^20.14.10",
"@types/node": "^24.0.0",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.2.22",
"axios": "^1.7.4",
"bootstrap": "^5.3.2",
"downloadjs": "^1.4.7",
"http-proxy-middleware": "^2.0.6",
"jquery": "^3.6.0",
"merge": "^2.1.1",
"oidc-client": "^1.11.5",
"pdf-lib": "^1.17.1",
"react": "^18.3.1",
"react-bootstrap": "^2.10.2",
"react-dom": "^18.2.0",
"react-redux": "^9.1.2",
"react-router-dom": "^6.17.0",
"react-scripts": "5.0.1",
"rimraf": "^5.0.5",
"typescript": "^5.2.2",
"workbox-background-sync": "^7.1.0",
"workbox-broadcast-update": "^7.1.0",
@@ -43,23 +40,20 @@
"workbox-streams": "^7.1.0"
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@vitejs/plugin-react": "^4.3.4",
"@types/downloadjs": "^1.4.4",
"cross-env": "^7.0.3",
"jsdom": "^25.0.1",
"less": "^4.2.0",
"less-loader": "^11.1.3"
"vite": "^5.4.10",
"vitest": "^2.1.3"
},
"scripts": {
"start": "rimraf ./build && react-scripts start",
"build": "react-scripts build",
"test": "cross-env CI=true react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
"dev": "vite",
"start": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "vitest run",
"test:watch": "vitest"
},
"browserslist": {
"production": [
@@ -72,10 +66,5 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"jest": {
"moduleNameMapper": {
"^axios$": "axios/dist/node/axios.cjs"
}
}
}
-46
View File
@@ -1,46 +0,0 @@
<!DOCTYPE html>
<html lang="hu">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Kém Karakter alkotási segédlet"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/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="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Merienda&display=swap" rel="stylesheet">
<title>Kém Karakter App</title>
</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`.
-->
</body>
</html>
+11
View File
@@ -1,7 +1,18 @@
import React from 'react';
import { render } from '@testing-library/react';
import { vi } from 'vitest';
import App from './App';
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual<typeof import('react-router-dom')>('react-router-dom');
return {
...actual,
createBrowserRouter: vi.fn(() => ({})),
RouterProvider: () => <div data-testid="router-provider" />,
};
});
test('renders App', () => {
render(<App faro={undefined}/>);
});
@@ -1,5 +1,5 @@
import React, {useState} from 'react';
import './CreateCharacter.css'
import './CreateCharacter.less'
import {Faj, TulajdonsagokFajjal} from "../domain-models/faj";
import {Osztaly, SetFelszerelesForChangedOsztaly} from "../domain-models/osztaly"
import FajSelector from "../components/FajSelector";
+2 -1
View File
@@ -1 +1,2 @@
/// <reference types="react-scripts" />
/// <reference types="vite/client" />
/// <reference types="vitest/globals" />
+5 -5
View File
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2020",
"lib": [
"dom",
"dom.iterable",
@@ -14,14 +14,14 @@
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"downlevelIteration": true
"jsx": "react-jsx"
},
"include": [
"src"
"src",
"vite.config.ts"
]
}
+22
View File
@@ -0,0 +1,22 @@
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const port = Number(env.PORT || 5173);
const https = env.HTTPS === 'true';
return {
plugins: [react()],
server: {
port,
https,
strictPort: true,
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: './vitest.setup.ts',
},
};
});
+1
View File
@@ -0,0 +1 @@
import '@testing-library/jest-dom/vitest';
+905 -9223
View File
File diff suppressed because it is too large Load Diff