npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@umajs/plugin-react-ssr

v2.0.9

Published

In umajs, React is used to develop the plug-in of SPA and MPA, which supports server-side rendering and client-side rendering

Downloads

16

Readme

@umajs/plugin-react-ssr

针对Umajs提供React服务端渲染模式的开发插件,插件基于服务端渲染骨架工具Srejs开发。

插件介绍

plugin-react-ssr插件扩展了Umajs中提供的统一返回处理Result对象,新增了reactView页面组件渲染方法,可在controller自由调用,使用类似传统模板引擎;也同时将方法挂载到了koa中间件中的ctx对象上;当一些公关的页面组件,比如404、异常提示页面、登录或者需要在中间件中拦截跳转时可以在middleware中调用。

插件安装

 yarn add @umajs/plugin-react-ssr --save

插件配置

// plugin.config.ts
export default <{ [key: string]: TPluginConfig }>{
    'react-ssr': {
        enable:true,
        options:{
            rootDir:'web', // 客户端页面组件根文件夹
            rootNode:'app', // 客户端页面挂载根元素ID
            ssr: true, // 全局开启服务端渲染
            cache: false, // 全局使用服务端渲染缓存 开发环境设置true无效
            prefixCDN: '/' // 客户端代码部署CDN前缀
        }
    }
};

web 目录结构

- web # rootDir配置可修改
        - pages # 固定目录
            - home #页面名称
                - index.tsx
                - index.scss

创建 react 页面组件

页面组件开发模式支持 js ,tsx。

import './home.scss'
import React from 'react'
type typeProps = {
  say: string
}
export default function (props: typeProps) {
  const { say } = props
  return <div className="ts-demo">{say}</div>
}

路由中使用插件

import { BaseController, Path } from '@umajs/core'
import { Result } from '@umajs/plugin-react-ssr'

export default class Index extends BaseController {
  @Path('/')
  index() {
    return Result.reactView(
      'home',
      { say: 'hi,I am a ReactView' },
      { cache: true }
    )
  }
}

使用文档

案例