Skip to content

Commit

Permalink
refactor: migrate create-react-app to vite
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Oct 10, 2024
1 parent 279c21d commit 10aa667
Show file tree
Hide file tree
Showing 16 changed files with 11,890 additions and 29,942 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env",
["@babel/preset-react", { "runtime": "automatic" }]
]
}
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }}
PACT_PROVIDER: pactflow-example-provider
PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP }}
REACT_APP_API_BASE_URL: http://localhost:3001
VITE_APP_API_BASE_URL: http://localhost:3001
GIT_COMMIT: ${{ github.sha }}
GIT_REF: ${{ github.ref }}

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ci: test publish_pacts can_i_deploy $(DEPLOY_TARGET)
# Use this for quick feedback when playing around with your workflows.
fake_ci: .env
@CI=true \
REACT_APP_API_BASE_URL=http://localhost:8080 \
VITE_APP_API_BASE_URL=http://localhost:8080 \
make ci

publish_pacts: .env
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Open a separate terminal for the consumer.
Before starting the consumer, create a `.env` file in the root of the project and set the URL to point to your running provider:

```bash
REACT_APP_API_BASE_URL=http://localhost:8080
VITE_APP_API_BASE_URL=http://localhost:8080
```

Then run:
Expand Down
1 change: 1 addition & 0 deletions public/index.html → index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<script type="module" src="/src/index.jsx"></script>
</body>
</html>
41,755 changes: 11,840 additions & 29,915 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 21 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.27.2",
"@vitejs/plugin-react": "^4.3.2",
"axios": "^1.7.7",
"prop-types": "15.8.1",
"react": "^18.2.0",
"react-dom": "18.2.0",
"react-router": "^6.4.2",
"react-router-dom": "^6.4.2",
"react-scripts": "5.0.1",
"spectre.css": "^0.5.9"
"react": "^18.3.1",
"react-dom": "18.3.1",
"react-router": "^6.26.2",
"react-router-dom": "^6.26.2",
"spectre.css": "^0.5.9",
"vite": "^5.4.8"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "cross-env CI=true react-scripts test",
"eject": "react-scripts eject",
"test:pact": "cross-env CI=true react-scripts test --testTimeout 30000 pact.spec.js"
"start": "vite",
"build": "vite build",
"test": "jest",
"preview": "vite preview",
"test:pact": "cross-env CI=true vite test --testTimeout 30000 pact.spec.js"
},
"eslintConfig": {
"extends": [
Expand All @@ -38,12 +39,14 @@
]
},
"devDependencies": {
"@babel/preset-react": "^7.18.6",
"@pact-foundation/pact": "^10.1.4",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@babel/preset-env": "^7.25.8",
"@babel/preset-react": "^7.25.7",
"@pact-foundation/pact": "^13.1.4",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"cross-env": "^7.0.3",
"dotenv": "^16.0.3"
"dotenv": "^16.4.5",
"jest": "^29.7.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 3 additions & 6 deletions src/api.js → src/api.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
const axios = require('axios').default;
const adapter = require('axios/lib/adapters/http');
import axios from 'axios';
import { Product } from './product';

axios.defaults.adapter = adapter;

export class API {
constructor(url) {
if (url === undefined || url === '') {
url = process.env.REACT_APP_API_BASE_URL;
url = process.env.VITE_APP_API_BASE_URL;
}
if (url.endsWith('/')) {
url = url.substr(0, url.length - 1);
Expand Down Expand Up @@ -48,5 +45,5 @@ export class API {
}

export default new API(
process.env.REACT_APP_API_BASE_URL || 'http://localhost:3001'
process.env.VITE_APP_API_BASE_URL || 'http://localhost:3001'
);
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig(() => {
return {
build: {
outDir: 'build',
commonjsOptions: { transformMixedEsModules: true }
},
plugins: [react()],
define: {
'process.env': process.env
}
};
});

0 comments on commit 10aa667

Please sign in to comment.