Skip to content

Commit

Permalink
perf: change react to preact to decrease bundle size and improve app …
Browse files Browse the repository at this point in the history
…performance
  • Loading branch information
Victor Fernandes committed Jan 9, 2024
1 parent 9df5886 commit a448501
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 218 deletions.
493 changes: 298 additions & 195 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@
"preview": "vite preview"
},
"dependencies": {
"@crxjs/vite-plugin": "^2.0.0-beta.15",
"@types/chrome": "^0.0.256",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"preact": "^10.19.3"
},
"devDependencies": {
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@crxjs/vite-plugin": "^2.0.0-beta.15",
"@types/chrome": "^0.0.256",
"@preact/preset-vite": "^2.8.1",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"typescript": "^5.2.2",
"vite": "^5.0.11"
}
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect, useState} from "react";
import { useEffect, useState } from "preact/hooks";
import './index.css'
import NoResults from "./components/no-results.tsx";
import Header from "./components/header.tsx";
Expand Down
6 changes: 3 additions & 3 deletions src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from "react";
import './button.css';
import { FunctionComponent } from "preact";

interface Props {
onClick: () => void;
children: React.ReactElement | string;
children: any;
type?: 'text' | 'primary' | 'secondary';
className?: string;
size?: 'small'
}

const Button: React.FC<Props> = ({ onClick, className, type = 'text', size = '', children }) => {
const Button: FunctionComponent<Props> = ({ onClick, className, type = 'text', size = '', children }) => {
return (
<button className={`btn ${className} ${type} ${size}`} onClick={onClick}>
{children}
Expand Down
9 changes: 2 additions & 7 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { render } from 'preact';
import App from './App.tsx';
import './index.css';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
render(<App />, document.getElementById('root')!);
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"paths": {
"react": ["./node_modules/preact/compat/"],
"react-dom": ["./node_modules/preact/compat/"]
},

/* Bundler mode */
"moduleResolution": "bundler",
Expand All @@ -13,6 +17,7 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"jsxImportSource": "preact",

/* Linting */
"strict": true,
Expand Down
4 changes: 2 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import preact from '@preact/preset-vite';
import { crx } from '@crxjs/vite-plugin';
import manifest from './manifest.json'

export default defineConfig({
plugins: [
react(),
preact(),
crx({ manifest }),
],
})

0 comments on commit a448501

Please sign in to comment.