Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-tsx

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-tsx

express view tsx render

  • 2.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33
increased by371.43%
Maintainers
1
Weekly downloads
 
Created
Source

介绍

这是 express 中 jsx 模板渲染的一个实现 .

它提供了两种渲染模式 , 一种 "静态渲染" , 一种 "服务器同构渲染"

静态渲染

调用 ReactDOM.renderToStaticMarkup 方法渲染 require('tsxmodule').default || require('tsxmodule')

app 主文件


import Express = require('express')
export const app = Express()

import { render } from "../";
app.engine('.tsx',render())
app.set('views',__dirname+'/views')
app.set('view engine','tsx')

app.get('/',(req,res)=>res.render('staticHTMLRender',{ who:'express-tsx', title:'express-tsx' }))

tsx 视图文件


export default (props)=>
<html lang="en">
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
  <title>{props.title}</title>
</head>
<body>
  hello {props.who}
</body>
</html>

服务器同构渲染

这个的实现就比较绕了 , 建议直接看 源码

app 主文件


import Express = require('express')
export const app = Express()

import { render } from "../";
app.engine('.tsx',render({ ssr:true }))
app.set('views',__dirname+'/views')
app.set('view engine','tsx')

app.get('/',(req,res)=>res.render('ssrRender',{ who:'express-tsx', title:'express-tsx' }))

tsx 视图文件


export default (props)=>
<div onClick={ ()=>alert(props.who) }>
  hello {props.who}
</div>

示例运行

  • 克隆本项目
    git clone https://github.com/shynome/express-tsx.git
    
  • 安装依赖
    npm install
    
  • 运行
    npm test
    
  • 在浏览器中打开 示例
  • 最后 , 如果有好的建议欢迎提 issue | pr 哦 !

Keywords

FAQs

Package last updated on 23 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc