mercuryseries/inertia-bundle

Inertia.js 的增强版 Symfony 适配器。

安装: 121

依赖者: 0

建议者: 0

安全: 0

星星: 6

关注者: 3

分支: 0

公开问题: 1

类型:symfony-bundle

0.1.0 2023-06-28 09:40 UTC

This package is auto-updated.

Last update: 2024-09-12 01:16:32 UTC


README

这是一个基于 rompetomp/inertia-bundle 的 Inertia.js 服务器端适配器的增强版本。

这个 Bundle 的灵感和一些 API/代码来源于 Laravel Inertia 适配器

安装

请确保全局已安装 Composer,如 Composer 文档的 安装章节 所述。

使用 Symfony Flex 的应用程序

打开命令行控制台,进入您的项目目录,然后执行

$ composer require mercuryseries/inertia-bundle

不使用 Symfony Flex 的应用程序

步骤 1: 下载 Bundle

打开命令行控制台,进入您的项目目录,然后执行以下命令以下载此 Bundle 的最新稳定版本

$ composer require mercuryseries/inertia-bundle

步骤 2: 启用 Bundle

然后,通过将其添加到项目 config/bundles.php 文件中注册的 Bundle 列表来启用该 Bundle

// config/bundles.php

return [
    // ...
    MercurySeries\Bundle\InertiaBundle\MercurySeriesInertiaBundle::class => ['all' => true],
];

步骤 3: 选择您的栈

--ssr 添加到以下任一选项中,以添加 服务器端渲染 (SSR) 支持

# React + Webpack Encore
$ symfony console inertia:install react --bundler=webpack

# React + Vite
$ symfony console inertia:install react --bundler=vite

# Vue + Webpack Encore
$ symfony console inertia:install vue --bundler=webpack

# Vue + Vite
$ symfony console inertia:install vue --bundler=vite

步骤 4: 路由配置

如果缺少,请添加以下路由配置

# config/routes.yaml

controllers:
    resource:
        path: ../src/Controller/
        namespace: App\Controller
    type: attribute
+   defaults:
+       csrf:
+           create: true
+           require:
+               - 'POST'
+               - 'PUT'
+               - 'PATCH'
+               - 'DELETE'

步骤 5: 安装包和编译资产

# Install npm and run:
$ npm install

# Start the development server:
$ npm run dev-server

# Start coding into assets/js/pages/ 🎉

生产环境

# First you need to build both client and server bundles
$ npm run build

# Start/Stop the SSR Server
$ symfony console inertia:start-ssr
$ symfony console inertia:stop-ssr