Preact

Addfox soporta usar Preact para desarrollar extensiones, proporcionando un tamaño de paquete más pequeño.

Instalación

Seleccionar plantilla Preact al crear el proyecto:

pnpm create addfox-app --framework preact

O instalar en proyecto existente:

pnpm
npm
yarn
bun
pnpm add @rsbuild/plugin-preact

Configuración

// addfox.config.ts
import { defineConfig } from "addfox";
import { pluginPreact } from "@rsbuild/plugin-preact";

export default defineConfig({
  plugins: [pluginPreact()],
});

Estructura del proyecto

app/
├── background/
│   └── index.ts
├── content/
│   └── index.tsx
├── popup/
│   ├── App.tsx
│   ├── index.html
│   └── index.tsx
└── manifest.json

Código de ejemplo

// app/popup/index.tsx
import { render } from 'preact';
import { App } from './App';
import './index.css';

render(<App />, document.getElementById('root')!);
// app/popup/App.tsx
import { useState } from 'preact/hooks';

export function App() {
  const [count, setCount] = useState(0);

  return (
    <div className="p-4">
      <h1 className="text-xl font-bold">Hello Preact!</h1>
      <button 
        onClick={() => setCount(c => c + 1)}
        className="mt-2 px-4 py-2 bg-blue-500 text-white rounded"
      >
        Count: {count}
      </button>
    </div>
  );
}

Hooks

Preact proporciona Hooks compatibles con React:

import { useState, useEffect, useCallback } from 'preact/hooks';

Enlaces relacionados