承接 yii2-extensions/inertia-react 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yii2-extensions/inertia-react

Composer 安装命令:

composer require yii2-extensions/inertia-react

包简介

React adapter helpers for inertia.

README 文档

README

Yii Framework

Inertia React


PHPUnit Mutation Testing PHPStan

React adapter helpers for yii2-extensions/inertia
React-friendly root view and Vite asset integration for Yii2 Inertia applications

Features

Feature Overview

Overview

yii2-extensions/inertia-react is a thin PHP-side adapter package for building React-based Inertia applications on top of yii2-extensions/inertia.

This package does not install npm dependencies for you. Instead, it provides.

  • a React-specific bootstrap class for Yii2;
  • a default root view that outputs Vite tags plus the initial Inertia page payload;
  • a Vite helper component for development-server and manifest-driven production assets;
  • React Refresh preamble output for @vitejs/plugin-react in development mode;
  • documentation and conventions for the application-owned React client entrypoint.

Installation

composer require yii2-extensions/inertia-react:^0.1

Register the React bootstrap class.

return [
    'bootstrap' => [
        \yii\inertia\react\Bootstrap::class,
    ],
    'components' => [
        'inertiaReact' => [
            'class' => \yii\inertia\Vite::class,
            'baseUrl' => '@web/build',
            'devMode' => YII_ENV_DEV,
            'devServerUrl' => 'http://localhost:5173',
            'entrypoints' => [
                'resources/js/app.jsx',
            ],
            'manifestPath' => '@webroot/build/.vite/manifest.json',
            'preambleProvider' => \yii\inertia\react\Bootstrap::reactRefreshPreambleProvider(),
        ],
    ],
];

Use only yii\inertia\react\Bootstrap::class in the bootstrap list. It already delegates the base yii2-extensions/inertia bootstrap.

React client entrypoint

Install the client-side dependencies in your application project.

npm install react react-dom @vitejs/plugin-react @inertiajs/react vite

Then create your client entrypoint, for example resources/js/app.jsx:

import { createInertiaApp } from "@inertiajs/react";
import { createElement } from "react";
import { createRoot } from "react-dom/client";

createInertiaApp({
  resolve: (name) => {
    const pages = import.meta.glob("./Pages/**/*.jsx", { eager: true });
    return pages[`./Pages/${name}.jsx`];
  },
  setup({ el, App, props }) {
    createRoot(el).render(createElement(App, props));
  },
});

Development mode and React Refresh

When devMode is true and preambleProvider is set to \yii\inertia\react\Bootstrap::reactRefreshPreambleProvider(), the Vite helper bypasses the production manifest and emits, in order: the React Refresh preamble, @vite/client, and each entrypoints script pointing at devServerUrl. Edits to .jsx files are hot reloaded without a full page refresh.

Run the Vite dev server and the Yii2 application side by side:

# Terminal 1 — Vite dev server
npm run dev

# Terminal 2 — Yii2 in dev mode
YII_ENV=dev ./yii serve

See Development Notes for the full HMR workflow, CORS notes, and troubleshooting.

Production asset integration

This package expects a Vite manifest file generated with build.manifest = true. In production it will render.

  1. style sheet tags for the entrypoint chunk and its imported chunks;
  2. module entry scripts for each entrypoint;
  3. optional modulepreload tags for imported JavaScript chunks.

Documentation

For detailed configuration options and advanced usage.

Package information

PHP Yii 22.0.x Latest Stable Version Total Downloads

Quality code

Codecov PHPStan Level Max Super-Linter StyleCI

License

License

统计信息

  • 总下载量: 403
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-04-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固