<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: phong phan</title>
    <description>The latest articles on Forem by phong phan (@phongphanq089).</description>
    <link>https://forem.com/phongphanq089</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1353476%2F6cb2141f-882f-40f1-b378-0d0a7d836bb0.png</url>
      <title>Forem: phong phan</title>
      <link>https://forem.com/phongphanq089</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/phongphanq089"/>
    <language>en</language>
    <item>
      <title>I’m thrilled to share my latest project with everyone – my personal portfolio! 🚀</title>
      <dc:creator>phong phan</dc:creator>
      <pubDate>Mon, 16 Sep 2024 07:42:18 +0000</pubDate>
      <link>https://forem.com/phongphanq089/im-thrilled-to-share-my-latest-project-with-everyone-my-personal-portfolio-4mdj</link>
      <guid>https://forem.com/phongphanq089/im-thrilled-to-share-my-latest-project-with-everyone-my-personal-portfolio-4mdj</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkyopgj482sx0j9umhxkl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkyopgj482sx0j9umhxkl.png" alt="Image description" width="800" height="397"&gt;&lt;/a&gt;&lt;br&gt;
✨ &lt;a href="https://phongphan.xyz" rel="noopener noreferrer"&gt;Introducing My New Portfolio! &lt;/a&gt;✨&lt;br&gt;
🌐 Built from the ground up using React and Next.js, this website showcases not only the projects I’ve worked on, but also my personal design style and how I approach technology. From the sleek UI/UX design to smooth interactions, you'll get a glimpse of the difference these technologies make!&lt;/p&gt;

&lt;p&gt;🎨 Feel free to explore and let me know what you think! This is a chance to see what I’m capable of, and who knows, we might get to collaborate in the future.&lt;br&gt;
👉 Link: &lt;a href="https://phongphan.xyz/" rel="noopener noreferrer"&gt;Check it out here!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Setup React Typescript with Vite &amp; ESLint</title>
      <dc:creator>phong phan</dc:creator>
      <pubDate>Fri, 26 Apr 2024 01:41:23 +0000</pubDate>
      <link>https://forem.com/phongphanq089/setup-react-typescript-with-vite-eslint-1nfk</link>
      <guid>https://forem.com/phongphanq089/setup-react-typescript-with-vite-eslint-1nfk</guid>
      <description>&lt;h2&gt;
  
  
  Setup React Typescript with Vite &amp;amp; ESLint
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd54myazcikrr2qvwdwwj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd54myazcikrr2qvwdwwj.png" alt="Image description" width="800" height="420"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://vitejs.dev/"&gt;Vite&lt;/a&gt; is trending recently, because of its simple setup and much faster execution speed than Webpack.&lt;/p&gt;
&lt;h2&gt;
  
  
  🥇ReactJs Vite folder structure
&lt;/h2&gt;

&lt;p&gt;Below is the complete directory structure of the ReactJs Typescript Vite ESLint Prettier project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;📦react-app
 ┣ 📂dist
 ┣ 📂public
 ┃ ┗ 📜vite.svg
 ┣ 📂src
 ┃ ┣ 📂assets
 ┃ ┃ ┗ 📜react.svg
 ┃ ┣ 📜App.css
 ┃ ┣ 📜App.tsx
 ┃ ┣ 📜index.css
 ┃ ┣ 📜main.tsx
 ┃ ┗ 📜vite-env.d.ts
 ┣ 📜.editorconfig
 ┣ 📜.eslintignore
 ┣ 📜.eslintrc.cjs
 ┣ 📜.gitignore
 ┣ 📜.prettierignore
 ┣ 📜.prettierrc
 ┣ 📜index.html
 ┣ 📜package-lock.json
 ┣ 📜package.json
 ┣ 📜tsconfig.json
 ┣ 📜tsconfig.node.json
 ┗ 📜vite.config.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;dist folder: Folder containing build files.&lt;/li&gt;
&lt;li&gt;Public folder: Contains index.html file and related files such as favicon.ico, robots.txt,...&lt;/li&gt;
&lt;li&gt;src folder: Contains our main source code.&lt;/li&gt;
&lt;li&gt;Folder src/assets: Contains media, css (the App.css and index.css files above I left intact when first created, you can put them in assets/styles for simplicity), fonts.&lt;/li&gt;
&lt;li&gt;The remaining config files will be introduced in the sections below.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🥇Step 1 - Create Vite project
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Vite requires Node version 14.18+, 16+ to operate stably. However, some templates require a higher version, so if it warns, please update nodejs to a higher version.&lt;br&gt;
You can use npm or yarn or pnpm, here I use npm for simplicity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;with npm&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm create vite@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with yarn&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn create vite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with PNPM&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm create vite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running, it will ask to enter a project name****&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Need to install the following packages:
  create-vite@4.1.0
Ok to proceed? (y) y
✔ Project name: … react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is to choose Framework&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✔ Select a framework: › React
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Select template, here I choose &lt;strong&gt;TypeScript + SWC&lt;/strong&gt;, SWC will replace Babel for compiling Typescript/Javascript code. &lt;strong&gt;SWC&lt;/strong&gt; is 20 times faster than &lt;strong&gt;Babel&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✔ Select a variant: › TypeScript + SWC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is the folder just created by Vite&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🥇Step 2 - Install related packages ESLint and Prettier&lt;/p&gt;

&lt;p&gt;After completing step 1, by default Vite has already helped us with basic configuration for ESLint and TypeScript, but to make coding easier, we will install some more packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i prettier eslint-config-prettier eslint-plugin-prettier -D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the things we install&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;prettier&lt;/strong&gt;: main formatter code
-** eslint-config-prettier**: ESLint config set to disable ESLint rules that conflict with Prettier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;eslint-plugin-prettier&lt;/strong&gt;: Use some additional Prettier rules for ESLint.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🥇Step 3 - Config ESlint to standardize the code&lt;br&gt;
Open the &lt;strong&gt;.eslintrc.cjs&lt;/strong&gt; file&lt;br&gt;
Add this value to the** ignorePatterns &lt;strong&gt;array, the purpose is that I do not want **ESLint&lt;/strong&gt; to check the &lt;strong&gt;vite.config.ts&lt;/strong&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'vite.config.ts'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following code to the &lt;strong&gt;extends&lt;/strong&gt; array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'eslint-config-prettier', 'prettier'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following code to the &lt;strong&gt;plugins&lt;/strong&gt; array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'prettier'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following code to the** rules **object to add Prettier rules&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'prettier/prettier': [
      'warn',
      {
        arrowParens: 'always',
        semi: false,
        trailingComma: 'none',
        tabWidth: 2,
        endOfLine: 'auto',
        useTabs: false,
        singleQuote: true,
        printWidth: 120,
        jsxSingleQuote: true
      }
    ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🥇Step 4 - Config Prettier to format the code&lt;/p&gt;

&lt;p&gt;Create a .prettierrc file in the folder in the root directory with the content below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "arrowParens": "always",
  "semi": false,
  "trailingComma": "none",
  "tabWidth": 2,
  "endOfLine": "auto",
  "useTabs": false,
  "singleQuote": true,
  "printWidth": 120,
  "jsxSingleQuote": true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The purpose is prettier configuration. You should install Extension &lt;strong&gt;Prettier - Code formatter&lt;/strong&gt; for VS Code so it can understand. Next Create a **.prettierignore **file in the root directory. The purpose is that Prettier ignores unnecessary files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules/
dist/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🥇Step 5 - Config editor to standardize editor configuration&lt;/p&gt;

&lt;p&gt;Create an .editorconfig file in the root directory.The purpose is to configure configs to synchronize editors with each other if the project has many participants.For VS Code to understand this file, install the Extension EditorConfig for VS Code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[*]
indent_size = 2
indent_style = space
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🥇Step 6 - Configure alias for tsconfig.json&lt;/p&gt;

&lt;p&gt;Adding an alias to the &lt;strong&gt;tsconfig.json **file will help VS Code understand and automatically import for us.&lt;br&gt;
Add this line to **compilerOptions&lt;/strong&gt; in file &lt;strong&gt;tsconfig.json&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"baseUrl": ".",
"paths": {
  "~/*": ["src/*"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The meaning of this paragraph is that we can import Login from '~/pages/Login' instead of import Login from '../../pages/Login'. Much shorter and easier to see!&lt;/p&gt;

&lt;p&gt;🥇Step 7 - Configure alias for vite vite.config.ts&lt;/p&gt;

&lt;p&gt;Install the** @types/node** package to use node js in the ts file without errors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @types/node -D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure alias and enable source map in file &lt;strong&gt;vite.config.ts&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    port: 3000
  },
  css: {
    devSourcemap: true
  },
  resolve: {
    alias: {
      '~': path.resolve(__dirname, './src')
    }
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🥇Step 8 - Update script for package.json&lt;/p&gt;

&lt;p&gt;Open the &lt;strong&gt;package.json&lt;/strong&gt; file, add the **script **below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    //...
    "lint:fix": "eslint --fix src --ext ts,tsx",
    "prettier": "prettier --check \"src/**/(*.tsx|*.ts|*.css|*.scss)\"",
    "prettier:fix": "prettier --write \"src/**/(*.tsx|*.ts|*.css|*.scss)\""
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🥇Command to run the project&lt;/p&gt;

&lt;p&gt;That's it, to run in the dev environment, we will run it with the &lt;strong&gt;npm run dev&lt;/strong&gt; command.&lt;/p&gt;

&lt;p&gt;If you want to build, &lt;strong&gt;npm run build&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are also some commands like.&lt;/li&gt;
&lt;li&gt;Preview the build results with the npm run preview command&lt;/li&gt;
&lt;li&gt;Check if the project has any errors related to ESLint: npm run lint.&lt;/li&gt;
&lt;li&gt;Automatically fix ESLint related errors (not everything can be fixed, but many can be fixed): npm run lint:fix&lt;/li&gt;
&lt;li&gt;Check if the project has any errors related to Prettier: npm run prettier.&lt;/li&gt;
&lt;li&gt;Automatically fix Prettier related errors: npm run prettier:fix.
Wishing you success!&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>vite</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
