@srejs/react是一个轻量级服务端渲染骨架工具,为koa社区的nodejs开发框架提供具有服务端渲染能力的工具包,使得类似umajs类的web开发框架可以更方便实现前后端同构的服务端渲染能力。特点:轻量级,模板式调用页面进行服务端渲染,不限制后端路由。


Keywords
ssr, react, react-ssr, @umajs/plugin-react-ssr, umajs-react-ssr, @srejs, nextjs
License
MIT
Install
npm install @srejs/react@1.3.2

Documentation


Server rendering engine, abbreviated as srejs, is the server-side rendering engine. It provides the simplest and most flexible react and Vue lightweight server-side rendering skeleton tool for each node development framework, and supports the use in any koa framework.

react vue License Node

Server rendering engine 缩写为 Srejs, 即服务器端渲染引擎,为各个node开发框架提供最简单,最灵活的React,Vue轻量级服务端渲染骨架工具,支持在任何koa框架中使用。

Development and debugging

yarn install
## debugg React
cd packages/app && npm start  

## debugg Vue2.0 
cd packages/app-vue && npm start 

## debugg Vue3.0
cd packages/app-vue3 && npm start 

Feature

  • 🚀 Support SSR and CSR(支持SSR和CSR)
  • 🚀 State management(redux/vuex)
  • 🚀 Initialize the component props on the server side(在服务端初始化组件Props)
  • 🚀 Nested Route(React-Router/Vue-Router)
  • 🚀 Customize HTML and SEO
  • 🚀 Support spa and mpa(单页面应用和多页面应用)
  • 🚀 Support page level build updates(按需构建指定页面编译)
  • 🚀 Support layout(@srejs/react支持)
  • 🚀 React16+
  • 🚀 Vue2.0
  • 🚀 Vue3.0

How to Use

Develop page components(React/Vue)

//web/pages/index/index.ts
import React from 'react'
export default function (props:any) {
  const { title } = props
  return <div className="ts-demo">{title}</div>
}

Use in koa Middleware

import koa from 'koa';
import srejs from '@srejs/react';
// import srejs from '@srejs/vue'; 

const app = new koa();
const Sre = new srejs(app,process.env.NODE_ENV != 'production',false); 
app.use((ctx,next)=>{
    Sre.render(ctx,'index',{title:'The page title'})
})
app.listen(8001);

Production

Page components need to be compiled in advance before deployment in the production environment

Add scripts configuration to the package.json

"scripts": {
    "build":"npx ssr build",
    "analyzer": "npx ssr analyzer",
},

Quick start

Questions

Please open an issue

License

MIT License

Copyright (c) 2021 dazjean