Skip to content

Commit 382fa67

Browse files
Miguel Angel Chimali CobanoMiguel Angel Chimali Cobano
authored andcommitted
update readme
1 parent 9ea1d88 commit 382fa67

File tree

15 files changed

+94
-216
lines changed

15 files changed

+94
-216
lines changed

04-frameworks/01-react/05-architecture/01-routes/readme.md

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ But if were importing this scene from a subfolder we would start having the
5454
dot dot hell, we could end up with imports like _../../../scenes/login_, why
5555
not creating aliases for the root folders that could be accessed in a simple way?
5656

57-
We can defined paths in _tsconfig_ and aliases in _webpack_ uuh wait but then
57+
We can defined paths in _tsconfig_ and aliases in _vite_ uuh wait but then
5858
we have to define similar stuff in two places, let's provide a solution that
5959
would avoid this, first of all we are going to define and _@_ alias in our
6060
_tsconfig.json_:
@@ -63,58 +63,32 @@ _tsconfig.json_
6363

6464
```diff
6565
"esModuleInterop": true,
66-
+ "baseUrl": "src",
66+
+ "baseUrl": "./src",
6767
+ "paths": {
6868
+ "@/*": ["*"]
6969
+ }
70-
},
7170
```
7271

73-
Cool now we could add this configuration to webpack (WAIT do not do that):
74-
75-
_webpack.config.json_
76-
77-
```diff
78-
resolve: {
79-
extensions: [".js", ".ts", ".tsx"],
80-
+ alias: {
81-
+ '@': path.resolve(__dirname, 'src'),
82-
+ },
83-
},
84-
```
85-
86-
But since we don't want to repeat code, let's see if somebody has
87-
implemented some magic to allow webpack read this configuration from
88-
the _tsconfig_
89-
90-
We have two approaches:
91-
92-
- Gist source code: https://gist.github.com/nerdyman/2f97b24ab826623bff9202750013f99e
93-
94-
- Webpack plugin: https://www.npmjs.com/package/tsconfig-paths-webpack-plugin
95-
96-
Let's go for the webpack plugin option:
72+
Let's install the library to allow Vite infer the aliases from the Typescript configuration:
9773

9874
```bash
99-
npm install tsconfig-paths-webpack-plugin --save-dev
75+
npm i vite-tsconfig-paths -D
10076
```
10177

10278
Now let's consume this plugin:
10379

104-
_./webpack.config.js_
80+
_./vite.config.ts_
10581

10682
```diff
107-
const HtmlWebpackPlugin = require("html-webpack-plugin");
108-
+ const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
109-
const path = require("path");
110-
const basePath = __dirname;
111-
112-
module.exports = {
113-
context: path.join(basePath, "src"),
114-
resolve: {
115-
extensions: [".js", ".ts", ".tsx"],
116-
+ plugins: [new TsconfigPathsPlugin()]
117-
},
83+
import { defineConfig } from "vite";
84+
import checker from "vite-plugin-checker";
85+
import react from "@vitejs/plugin-react";
86+
+ import tsconfigPaths from "vite-tsconfig-paths";
87+
88+
export default defineConfig({
89+
- plugins: [checker({ typescript: true }), react()],
90+
+ plugins: [tsconfigPaths(), checker({ typescript: true }), react()],
91+
});
11892
```
11993

12094
Now we can update the imports to use the new _@_ alias.

04-frameworks/01-react/05-architecture/01-routes/readme_es.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Instalamos la librería para permitir que Vite extraiga los alias de la cofigura
7575
npm i vite-tsconfig-paths -D
7676
```
7777

78+
Usamos el plugin en Vite:
79+
7880
_./vite.config.ts_
7981

8082
```diff

04-frameworks/01-react/05-architecture/07-css-handling/.babelrc

Lines changed: 0 additions & 7 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="utf-8" />
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6-
<meta name="viewport" content="width=device-width, initial-scale=1" />
7-
<title>My App Example</title>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Architecture</title>
87
</head>
8+
99
<body>
1010
<div id="root"></div>
11+
<script type="module" src="/src/index.tsx"></script>
1112
</body>
1213
</html>
Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,29 @@
11
{
2-
"name": "react-example",
3-
"version": "1.0.0",
4-
"description": "",
5-
"main": "index.js",
2+
"name": "hello-vite",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
66
"scripts": {
7-
"start": "run-p -l type-check:watch start:dev",
8-
"type-check": "tsc --noEmit",
9-
"type-check:watch": "npm run type-check -- --watch",
10-
"start:dev": "webpack-dev-server --mode development --open",
11-
"build": "rimraf dist && webpack --mode development"
7+
"start": "vite --host",
8+
"build": "vite build",
9+
"preview": "vite preview"
1210
},
13-
"author": "",
14-
"license": "ISC",
1511
"devDependencies": {
16-
"@babel/cli": "^7.17.10",
17-
"@babel/core": "^7.17.10",
18-
"@babel/preset-env": "^7.17.10",
19-
"@babel/preset-react": "^7.17.12",
20-
"@babel/preset-typescript": "^7.16.7",
21-
"@types/react": "^18.0.9",
22-
"@types/react-dom": "^18.0.4",
23-
"babel-loader": "^8.2.5",
24-
"css-loader": "^6.7.1",
25-
"html-loader": "^3.1.0",
26-
"html-webpack-plugin": "^5.5.0",
27-
"npm-run-all": "^4.1.5",
28-
"rimraf": "^3.0.2",
29-
"style-loader": "^3.3.1",
30-
"tsconfig-paths-webpack-plugin": "^3.5.2",
31-
"typescript": "^4.6.4",
32-
"webpack": "^5.72.1",
33-
"webpack-cli": "^4.9.2",
34-
"webpack-dev-server": "^4.9.0"
12+
"@types/react": "^19.1.8",
13+
"@types/react-dom": "^19.1.6",
14+
"@vitejs/plugin-react": "^5.0.2",
15+
"typescript": "^5.8.3",
16+
"vite": "^7.0.4",
17+
"vite-plugin-checker": "^0.10.0",
18+
"vite-tsconfig-paths": "^5.1.4"
3519
},
3620
"dependencies": {
3721
"@lemoncode/fonk": "^1.5.4",
3822
"@lemoncode/fonk-formik": "^4.0.1",
39-
"classnames": "^2.3.1",
40-
"formik": "^2.2.9",
41-
"react": "^18.1.0",
42-
"react-dom": "^18.1.0",
43-
"react-router-dom": "^6.3.0"
23+
"classnames": "^2.5.1",
24+
"formik": "^2.4.6",
25+
"react": "^19.1.0",
26+
"react-dom": "^19.1.0",
27+
"react-router-dom": "^7.8.2"
4428
}
4529
}

04-frameworks/01-react/05-architecture/07-css-handling/src/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
33
import { RouterComponent } from "@/core";
44
import { ProfileProvider } from "@/core/profile";
5+
import "@/global-css/styles.css";
56

67
export const App = () => {
78
return (

04-frameworks/01-react/05-architecture/07-css-handling/src/core/profile/profile.context.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ export const ProfileContext = React.createContext<Context>({
1515
),
1616
});
1717

18-
interface Props {
19-
children: React.ReactNode;
20-
}
21-
22-
export const ProfileProvider: React.FC<Props> = ({ children }) => {
18+
export const ProfileProvider: React.FC<React.PropsWithChildren> = ({
19+
children,
20+
}) => {
2321
const [userProfile, setUserProfile] = React.useState<UserProfile>(
2422
createEmptyUserProfile()
2523
);

04-frameworks/01-react/05-architecture/07-css-handling/src/global-css/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.layout-center {
2+
background-color: red;
23
display: grid;
34
grid-template-columns: 1fr;
45
align-items: center;

04-frameworks/01-react/05-architecture/07-css-handling/src/layouts/app.layout.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import React from "react";
22
import { ProfileContext } from "@/core/profile";
33

4-
interface Props {
5-
children: React.ReactNode;
6-
}
7-
8-
export const AppLayout: React.FC<Props> = ({ children }) => {
4+
export const AppLayout: React.FC<React.PropsWithChildren> = ({ children }) => {
95
const { userName } = React.useContext(ProfileContext);
106

117
return (
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import React from "react";
22

3-
interface Props {
4-
children: React.ReactNode;
5-
}
6-
7-
export const CenterLayout: React.FC<Props> = ({ children }) => (
8-
<div className="layout-center">{children}</div>
9-
);
3+
export const CenterLayout: React.FC<React.PropsWithChildren> = ({
4+
children,
5+
}) => <div className="layout-center">{children}</div>;

0 commit comments

Comments
 (0)