korium / redux-react-ssr
1.0.2
2017-01-17 02:44 UTC
Requires
- php: >=7.1.0
- ext-v8js: >=1.3.0
- phpv8/v8js-stubs: ~1.2
- reactjs/react-php-v8js: ^2.0
Requires (Dev)
- phpmd/phpmd: ~2.4
- phpunit/phpunit: ~4.8 || ~5.0
- squizlabs/php_codesniffer: ~2.6
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"