korium/redux-react-ssr

该软件包已被 废弃 且不再维护。作者建议使用 koriym/baracoa 软件包代替。

使用 v8js 进行 Redux ReactJS 服务器端渲染

1.0.2 2017-01-17 02:44 UTC

This package is auto-updated.

Last update: 2022-02-01 12:58:42 UTC


README

请使用 Koriym.Baracoa。一个 Redux-React-SSR 示例 可用。

redux-react-ssr

redux-react-ssr 是一个库,它利用 Facebook 的 React Redux 库的强大功能,在服务器端以及客户端渲染 UI 组件。

先决条件

  • php7.1
  • V8Js(开发时可选)

使用方法

<?php
require dirname(__DIR__, 3) . '/vendor/autoload.php';

use Koriym\ReduxReactSsr\ReduxReactJs;

$ssr = new ReduxReactJs(
    file_get_contents(__DIR__ . '/build/react.bundle.js'),
    file_get_contents(__DIR__ . '/build/app.bundle.js'),
    new ExceptionHandler(),
    new V8Js()
);
$view = $ssr('App', ['hello' => ['message' => 'Hello, Redux!']], 'root');
$html = <<<EOT
<!DOCTYPE html>
<html>
  <head>
    <title></title>
  </head>
  <body>
    <div id="root">{$view->markup}</div>
    <script src="build/react.bundle.js"></script>
    <script src="build/app.bundle.js"></script>
    <script>{$view->js}</script>
  </body>
</html>
EOT;

echo $html;

没有 V8Js 环境

即使没有 V8Js 扩展,也可以用于开发。在这种情况下,Render 方法不返回任何标记,但可以无错误地仅通过客户端渲染。

安装

composer require koriym/redux-react-ssr

测试 redux-react-ssr

git clone git@github.com:koriym/Koriym.ReduxReactSsr.git
composer install
cd Koriym.ReduxReactSsr/example/redux
npm install
npm run build
npm start

安装 V8Js

OSX

brew update
brew install homebrew/php/php71-v8js

编辑 php.ini 或添加 'V8Js.ini'

extension="/usr/local/opt/php71-v8js/v8js.so"