mercuryseries / inertia-bundle
Inertia.js 的增强版 Symfony 适配器。
0.1.0
2023-06-28 09:40 UTC
Requires
- php: ^7.4|^8.1
- dneustadt/csrf-cookie-bundle: ^1.0
- friendsofsymfony/jsrouting-bundle: ^2.8|^3.2
- rompetomp/inertia-bundle: ^2.4
- symfony/config: ^5.0|^6.0
- symfony/console: ^5.0|^6.0
- symfony/dependency-injection: ^5.0|^6.0
- symfony/form: ^5.0|^6.0
- symfony/http-kernel: ^5.0|^6.0
- symfony/process: ^5.0|^6.0
- symfony/serializer-pack: ^1.2
- symfony/twig-bundle: ^5.0|^6.0
Requires (Dev)
- laravel/pint: ^1.10
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