> ## Documentation Index
> Fetch the complete documentation index at: https://extension.js.org/llms.txt
> Use this file to discover all available pages before exploring further.

# 面向 React、Vue 及更多框架的扩展项目模板

> 通过官方 Extension.js 模板脚手架生成 React、Vue、Svelte、TypeScript 与原生 JS 的浏览器扩展，无需从零搭建。

通过从官方模板脚手架生成扩展，跳过手动搭建目录结构与配置，更快地起步。

## 模板能力

* **就绪的项目结构：** 从一份可用的 manifest、脚本与源码布局开始。
* **针对技术栈的设置：** 按照框架与运行时需求选择模板。
* **更快的上手：** 几分钟之内从想法到可运行的扩展。
* **一致的默认配置：** 减少项目之间和团队成员之间的设置漂移。

## 快速使用

<CodeGroup>
  ```bash npm theme={null}
  npx extension@latest create my-extension --template=<slug>
  ```

  ```bash pnpm theme={null}
  pnpx extension@latest create my-extension --template=<slug>
  ```

  ```bash yarn theme={null}
  yarn dlx extension@latest create my-extension --template=<slug>
  ```

  ```bash bun theme={null}
  bunx extension@latest create my-extension --template=<slug>
  ```
</CodeGroup>

把 `<slug>` 替换为你想要的模板名。

## 可用模板

选择与你项目匹配的默认技术栈。每张卡片都会脚手架生成一个最小可运行的扩展，并附带可用的 `manifest.json`。

<CardGroup cols={2}>
  <Card title="JavaScript" href="/docs/getting-started/templates/javascript">
    <div className="flex items-center gap-4">
      <img src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/javascript/javascript-original.svg" alt="JavaScript" width="40" height="40" />

      <span className="text-sm text-gray-600 dark:text-gray-300">
        原生 ES 模块，无编译步骤。最快的起步方式。
      </span>
    </div>
  </Card>

  <Card title="TypeScript" href="/docs/getting-started/templates/typescript">
    <div className="flex items-center gap-4">
      <img src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/typescript/typescript-original.svg" alt="TypeScript" width="40" height="40" />

      <span className="text-sm text-gray-600 dark:text-gray-300">
        在 popup、content 与 background 脚本中提供严格类型。
      </span>
    </div>
  </Card>

  <Card title="Svelte" href="/docs/getting-started/templates/svelte">
    <div className="flex items-center gap-4">
      <img src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/svelte/svelte-original.svg" alt="Svelte" width="40" height="40" />

      <span className="text-sm text-gray-600 dark:text-gray-300">
        编译时 UI 加上极小的运行时，适合 content script。
      </span>
    </div>
  </Card>

  <Card title="Vue" href="/docs/getting-started/templates/vue">
    <div className="flex items-center gap-4">
      <img src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/vuejs/vuejs-original.svg" alt="Vue" width="40" height="40" />

      <span className="text-sm text-gray-600 dark:text-gray-300">
        为 popup、options 与 content script 接好的单文件组件。
      </span>
    </div>
  </Card>

  <Card title="Preact" href="/docs/getting-started/templates/preact">
    <div className="flex items-center gap-4">
      <img src="https://preactjs.com/branding/symbol.svg" alt="Preact" width="40" height="40" />

      <span className="text-sm text-gray-600 dark:text-gray-300">
        React API 配 3kB 运行时。在意打包体积时是不错的选择。
      </span>
    </div>
  </Card>

  <Card title="React" href="/docs/getting-started/templates/react">
    <div className="flex items-center gap-4">
      <img src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/react/react-original.svg" alt="React" width="40" height="40" />

      <span className="text-sm text-gray-600 dark:text-gray-300">
        基于组件的 UI，完整支持 Manifest V3，并为 popup 与 options 接好了热模块替换。
      </span>
    </div>
  </Card>
</CardGroup>

想要带有鉴权、支付、设计系统与完整应用骨架的生产级起步项目？请在 [extension.dev](https://extension.dev) 浏览高级模板。

## 工作原理

当你运行 `create --template=<slug>` 时，Extension.js 会拉取所选模板，脚手架生成项目文件，并可选地安装依赖。

## 更多模板

在示例仓库中查找官方模板源码：

* [extension-js/examples](https://github.com/extension-js/examples/tree/main/examples)

模板目录名直接对应 `--template=<slug>`。

## 最佳实践

* 使用模板快速搭建项目。
* 从你已经熟悉的技术栈对应的模板开始。
* 根据项目需求，选择最契合的浏览器扩展上下文。

## 下一步

* 了解 [浏览器运行器](/docs/browsers/browsers-available) 如何帮助你验证扩展行为。
* 了解 Extension.js 如何处理 [环境变量](/docs/features/environment-variables)。

***
