Skip to content

Commit 1d05bd4

Browse files
committed
refactor: migrate from CRA to Vite
1 parent 6c7dc12 commit 1d05bd4

15 files changed

+110
-137
lines changed

.env

-2
This file was deleted.

.eslintrc.js

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ module.exports = {
1313
},
1414
},
1515
extends: [
16-
'react-app',
17-
'react-app/jest',
1816
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
1917
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
2018
],

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dist/
1+
build/

.prettierrc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
semi: false,
3-
trailingComma: "all",
3+
trailingComma: 'all',
44
singleQuote: true,
55
printWidth: 100,
6-
tabWidth: 2
7-
};
6+
tabWidth: 2,
7+
}

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ Within the download you'll find the following directories and files, logically g
116116
```
117117
coreui-free-react-admin-template
118118
├── public/ # static files
119-
│ └── index.html # html template
119+
│ ├── favicon.ico
120+
│ └── manifest.json
120121
121122
├── src/ # project root
122123
│ ├── assets/ # images, icons, etc.
@@ -126,12 +127,15 @@ coreui-free-react-admin-template
126127
│ ├── views/ # application views
127128
│ ├── _nav.js # sidebar navigation config
128129
│ ├── App.js
129-
│ ├── ...
130130
│ ├── index.js
131131
│ ├── routes.js # routes config
132132
│ └── store.js # template state example
133133
134-
└── package.json
134+
├── index.html # html template
135+
├── ...
136+
├── package.json
137+
├── ...
138+
└── vite.config.mjs # vite config
135139
```
136140

137141
## Documentation

index.html

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<!--
3+
* CoreUI Free React.js Admin Template
4+
* @version v5.0.0-rc.0
5+
* @link https://coreui.io/product/free-react-admin-template/
6+
* Copyright (c) 2024 creativeLabs Łukasz Holeczek
7+
* Licensed under MIT (https://github.com/coreui/coreui-free-react-admin-template/blob/main/LICENSE)
8+
-->
9+
<html lang="en">
10+
<head>
11+
<meta charset="utf-8">
12+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
13+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
14+
<meta name="description" content="CoreUI for React - Open Source Bootstrap Admin Template">
15+
<meta name="author" content="Łukasz Holeczek">
16+
<meta name="keyword" content="Bootstrap,Admin,Template,Open,Source,CSS,SCSS,HTML,RWD,Dashboard,React">
17+
<title>CoreUI Free React.js Admin Template</title>
18+
<link rel="manifest" href="/manifest.json">
19+
<link rel="shortcut icon" href="/favicon.ico">
20+
</head>
21+
<body>
22+
<noscript>
23+
You need to enable JavaScript to run this app
24+
</noscript>
25+
<div id="root"></div>
26+
<script type="module" src="/src/index.js"></script>
27+
<!-- built files will be auto injected -->
28+
</body>
29+
</html>

jest.config.js

-17
This file was deleted.

jsconfig.json

-6
This file was deleted.

package.json

+10-17
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
"license": "MIT",
1414
"author": "The CoreUI Team (https://github.com/orgs/coreui/people)",
1515
"scripts": {
16-
"build": "react-scripts build",
17-
"eject": "react-scripts eject",
16+
"build": "vite build",
1817
"lint": "eslint \"src/**/*.js\"",
19-
"start": "react-scripts start",
20-
"test": "react-scripts test",
21-
"test:cov": "npm test -- --coverage --watchAll=false",
22-
"test:debug": "react-scripts --inspect-brk test --runInBand"
18+
"serve": "vite preview",
19+
"start": "vite"
2320
},
2421
"dependencies": {
2522
"@coreui/chartjs": "^4.0.0-rc.0",
@@ -35,27 +32,23 @@
3532
"core-js": "^3.36.0",
3633
"prop-types": "^15.8.1",
3734
"react": "^18.2.0",
38-
"react-app-polyfill": "^3.0.0",
3935
"react-dom": "^18.2.0",
4036
"react-redux": "^9.1.0",
4137
"react-router-dom": "^6.22.3",
4238
"redux": "5.0.1",
4339
"simplebar-react": "^3.2.4"
4440
},
4541
"devDependencies": {
46-
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
47-
"@testing-library/jest-dom": "^6.4.2",
48-
"@testing-library/react": "^14.2.1",
49-
"@testing-library/user-event": "^14.5.2",
42+
"@vitejs/plugin-react": "^4.2.1",
43+
"autoprefixer": "^10.4.18",
44+
"eslint": "^8.57.0",
5045
"eslint-config-prettier": "^9.1.0",
5146
"eslint-plugin-prettier": "^5.1.3",
47+
"eslint-plugin-react": "^7.34.0",
48+
"eslint-plugin-react-hooks": "^4.6.0",
49+
"postcss": "^8.4.35",
5250
"prettier": "3.2.5",
53-
"react-scripts": "5.0.1",
5451
"sass": "^1.71.1",
55-
"web-vitals": "^3.5.2"
56-
},
57-
"engines": {
58-
"node": ">=10",
59-
"npm": ">=6"
52+
"vite": "^5.1.6"
6053
}
6154
}

public/index.html

-50
This file was deleted.

src/App.test.js

-9
This file was deleted.

src/index.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
import 'react-app-polyfill/stable'
2-
import 'core-js'
31
import React from 'react'
42
import { createRoot } from 'react-dom/client'
5-
import App from './App'
6-
import reportWebVitals from './reportWebVitals'
73
import { Provider } from 'react-redux'
4+
import 'core-js'
5+
6+
import App from './App'
87
import store from './store'
98

109
createRoot(document.getElementById('root')).render(
1110
<Provider store={store}>
1211
<App />
1312
</Provider>,
1413
)
15-
16-
// If you want to start measuring performance in your app, pass a function
17-
// to log results (for example: reportWebVitals(console.log))
18-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
19-
reportWebVitals()

src/reportWebVitals.js

-13
This file was deleted.

src/setupTests.js

-5
This file was deleted.

vite.config.mjs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { defineConfig, loadEnv } from 'vite'
2+
import react from '@vitejs/plugin-react'
3+
import path from 'node:path'
4+
import autoprefixer from 'autoprefixer'
5+
6+
export default defineConfig(({ mode }) => {
7+
// Load .env
8+
const env = loadEnv(mode, process.cwd(), '')
9+
process.env = { ...process.env, ...env }
10+
11+
return {
12+
base: './',
13+
build: {
14+
outDir: 'build',
15+
},
16+
css: {
17+
postcss: {
18+
plugins: [
19+
autoprefixer({}), // add options if needed
20+
],
21+
},
22+
},
23+
define: {
24+
// vitejs does not support process.env so we have to redefine it
25+
'process.env': process.env,
26+
},
27+
esbuild: {
28+
loader: 'jsx',
29+
include: /src\/.*\.jsx?$/,
30+
exclude: [],
31+
},
32+
optimizeDeps: {
33+
force: true,
34+
esbuildOptions: {
35+
loader: {
36+
'.js': 'jsx',
37+
},
38+
},
39+
},
40+
plugins: [react()],
41+
resolve: {
42+
alias: [
43+
{
44+
find: 'src/',
45+
replacement: `${path.resolve(__dirname, 'src')}/`,
46+
},
47+
],
48+
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.scss'],
49+
},
50+
server: {
51+
port: 3000,
52+
proxy: {
53+
// https://vitejs.dev/config/server-options.html
54+
},
55+
},
56+
}
57+
})

0 commit comments

Comments
 (0)