Skip to content

Commit 284ab5c

Browse files
committed
Added Vite section to home page
1 parent 5e4ed61 commit 284ab5c

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

src/App.jsx

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,134 @@ function App() {
192192
<CodeBlock code={serverCode} language="javascript" />
193193
</Paragraph>
194194

195+
<Title level={3}>Subsequent Migration to Vite</Title>
196+
<Paragraph>
197+
After initially building this site with Create React App (CRA), I migrated it to <a href="https://vite.dev">Vite</a> for better performance, modern tooling, and to eliminate security vulnerabilities found in CRA's dependencies.
198+
</Paragraph>
199+
200+
<Paragraph>
201+
<strong>Why migrate from CRA to Vite?</strong>
202+
<ul style={{ margin: "1.5em", lineHeight: "1.8" }}>
203+
<li><strong>Security:</strong> CRA is no longer maintained and had 9 vulnerabilities in dependencies</li>
204+
<li><strong>Performance:</strong> Vite dev server starts in ~100ms vs CRA's 2000ms+</li>
205+
<li><strong>Modern tooling:</strong> ES modules, better tree-shaking, Hot Module Replacement</li>
206+
<li><strong>Active development:</strong> Vite is actively maintained with regular updates</li>
207+
</ul>
208+
</Paragraph>
209+
210+
<Title level={4}>Migration Process</Title>
211+
<Paragraph>
212+
The migration involved several key steps to transition from CRA's webpack-based build system to Vite's modern ESBuild-powered toolchain:
213+
</Paragraph>
214+
215+
<Paragraph>
216+
<strong>1. Dependency Management:</strong><br/>
217+
Removed all CRA-specific packages and installed Vite:
218+
<CodeBlock code={`# Remove CRA dependencies
219+
npm uninstall react-scripts @testing-library/jest-dom @testing-library/react @testing-library/user-event web-vitals
220+
221+
# Install Vite and React plugin
222+
npm install --save-dev vite @vitejs/plugin-react`} language="bash" />
223+
</Paragraph>
224+
225+
<Paragraph>
226+
<strong>2. Configuration Setup:</strong><br/>
227+
Created a <code>vite.config.js</code> to handle JSX in .js files and maintain the same build output structure:
228+
<CodeBlock code={`import { defineConfig } from 'vite'
229+
import react from '@vitejs/plugin-react'
230+
231+
export default defineConfig({
232+
plugins: [react({
233+
include: "**/*.{jsx,js}"
234+
})],
235+
server: {
236+
port: 3000,
237+
open: true
238+
},
239+
build: {
240+
outDir: 'build' // Keep same output directory for compatibility
241+
},
242+
esbuild: {
243+
loader: 'jsx',
244+
include: /src\/.*\.(jsx?|tsx?)$/,
245+
},
246+
optimizeDeps: {
247+
esbuildOptions: {
248+
loader: {
249+
'.js': 'jsx'
250+
}
251+
}
252+
}
253+
})`} language="javascript" />
254+
</Paragraph>
255+
256+
<Paragraph>
257+
<strong>3. HTML Template Migration:</strong><br/>
258+
Moved <code>public/index.html</code> to the project root and updated it for Vite's module system:
259+
<CodeBlock code={`<!-- Updated for Vite -->
260+
<script type="module" src="/src/index.jsx"></script>
261+
262+
<!-- Replaced CRA's %PUBLIC_URL% tokens with direct paths -->
263+
<link rel="icon" href="/favicon.ico" />
264+
<link rel="manifest" href="/manifest.json" />`} language="html" />
265+
</Paragraph>
266+
267+
<Paragraph>
268+
<strong>4. File Extensions and Imports:</strong><br/>
269+
Renamed JavaScript files containing JSX to use .jsx extensions for proper Vite handling:
270+
<CodeBlock code={`# Renamed files for proper JSX recognition
271+
mv src/index.js src/index.jsx
272+
mv src/App.js src/App.jsx
273+
mv src/components/CodeBlock.js src/components/CodeBlock.jsx
274+
275+
# Updated import statements to include .jsx extension
276+
import App from './App.jsx';
277+
import CodeBlock from './components/CodeBlock.jsx';`} language="bash" />
278+
</Paragraph>
279+
280+
<Paragraph>
281+
<strong>5. Package.json Scripts:</strong><br/>
282+
Updated npm scripts to use Vite commands while maintaining compatibility:
283+
<CodeBlock code={`{
284+
"scripts": {
285+
"dev": "vite", // New: Fast development server
286+
"build": "vite build", // Same command, different tool
287+
"preview": "vite preview", // New: Preview production build
288+
"start": "vite" // Alias for convenience
289+
}
290+
}`} language="json" />
291+
</Paragraph>
292+
293+
<Paragraph>
294+
<strong>6. Cleanup and Testing:</strong><br/>
295+
Removed unused CRA-specific files and ensured full compatibility:
296+
<CodeBlock code={`# Removed unused files
297+
rm src/reportWebVitals.js
298+
299+
# Removed web-vitals import from index.jsx
300+
# Updated antd CSS import path for Vite compatibility
301+
302+
# Testing commands
303+
npm run dev # Fast development server
304+
npm run build # Production build (same output location)
305+
npm run preview # Test production build locally`} language="bash" />
306+
</Paragraph>
307+
308+
<Paragraph>
309+
<strong>Deployment Compatibility:</strong><br/>
310+
The migration was designed to be completely transparent to the existing deployment pipeline. The GitHub Actions workflow, server.js file, and FTP deployment process required <em>zero changes</em> because:
311+
<ul style={{ margin: "1.5em", lineHeight: "1.8" }}>
312+
<li>Vite outputs to the same <code>./build/</code> directory</li>
313+
<li><code>npm run build</code> command remains identical</li>
314+
<li>Generated static files are served the same way by Express.js</li>
315+
<li>React Router handling in server.js works unchanged</li>
316+
</ul>
317+
</Paragraph>
318+
319+
<Paragraph>
320+
<strong>Results:</strong> Zero security vulnerabilities, 20x faster development builds, modern tooling, and a completely seamless deployment process. The migration eliminated all technical debt from the unmaintained CRA while maintaining 100% functionality and deployment compatibility.
321+
</Paragraph>
322+
195323
<Divider />
196324

197325
{/* About Me Section */}

0 commit comments

Comments
 (0)