承接 zoilorys/craft-react-external-server 相关项目开发

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

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

zoilorys/craft-react-external-server

Composer 安装命令:

composer require zoilorys/craft-react-external-server

包简介

Client and Server-side React rendering for CraftCMS using external server

README 文档

README

Craft CMS React Renderer lets you implement React.js client and server-side rendering in your Craft CMS projects, leveraging external node.js server to render.

This is a fork of Alexandre Kilian's project craft-react, that is implemented using PhpExecJsReactRenderer, which requires php-v8js extension in order to run, which can be pain to setup in certain cases. This is a rewrite of the plugin, leveraging ExternalServerReactRenderer, which requires you to run external node.js server to render for you, which you have to run separately, but you can just use nodemon to handle restarts, so it's barely an issue to maintain it. Check Symfony React Sandbox for an example of this external server. For a complete documentation of the core functionality and client examples, as well as problems related to the Renderer itself, please check out ReactBundle or Symfony React Sandbox.

Why Server-Side rendering?

By rendering your react components on the server, you not only increase performance and search engine readability for SEO but also enable users with slower connections to be able to access your information before your client bundle has completely loaded.

How it works

Please checkout the Walkthrough for a step by step explanation of the client and twig-side of this plugin. For a JSON-API, we recommend Elements API for Craft CMS.

Installation

To install the plugin, follow these instructions:

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require zoilorys/craft-react-external-server
    

In the Control Panel, go to Settings → Plugins and click the “Install” button for Craft React.

Setup

In the plugin settings, add the following entry:

Environment: "client_side", "server_side" or "both"

or override the settings globally in config/react.php

And add NODE_SOCK_PATH to .env with your node.sock file location (refer to Symfony React Sandbox/external-server.js for usage)

<?php

return [
    'env' => 'client_side',
];

In your template, add the following TWIG-function where you want your react application to be rendered into:

    {{ react_component('MyApp', {'props': {entry: entry}}) }}

In the props, pass whatever props you want to pass to your root component.

Serialization

In order to serialize your entries to create a store or props, the new twig function serialize(entry, schema = 'entry', group = 'default') has been introduced. This allows you to create a php file to serialize your entries. Files should be located in config/react and should be named [schema].php. If unspecified, the schema will default to entry.php and the group to default.

<?php
# config/react/entry.php

use craft\elements\Entry;

return [
    'default' => function(Entry $entry){// named after the group
        return [
            'id' => $entry->id,
            'title' => $entry->title,
            'customField' => $entry->customField,
         ];
    }
];

To use it in twig, just pass your current entry and use the result in your store:

{# _entry.twig #}

{% set serializedBlogPost = serialize(entry,'blog', 'detail') %}
{{ react_component('MyApp', {'props': {blogpost: serializedBlogPost}}) }}

This will use the file config/react/blog.php

<?php
# config/react/blog.php

use craft\elements\Entry;

return [
    'detail' => function(Entry $entry){
        return [
            'id' => $entry->id,
            'title' => $entry->title,
            'content' => $entry->content,// custom field
         ];
    }
];

zoilorys/craft-react-external-server 适用场景与选型建议

zoilorys/craft-react-external-server 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「twig」 「react」 「Craft」 「reactjs」 「isomorphic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 zoilorys/craft-react-external-server 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 zoilorys/craft-react-external-server 我们能提供哪些服务?
定制开发 / 二次开发

基于 zoilorys/craft-react-external-server 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-07