介绍
express 视图引擎 tsx 的实现 .
安装
npm install express-tsx typescript --save
使用示例
主文件
const { expressTsx,expressTsxMiddleware } = require('../')
const server = expressTsx(__dirname)
server.locals.hotreload = true
server.listen(9000,function(){ console.log(`server is running on ${this.address().port}`) })
server.use(expressTsxMiddleware)
require('./requirejs.config')
server.use(/\/$/,(req,res)=>{
if(!req.query.callback){ return res.render('./hello.tsx') }
res.jsonp({word:'world'})
})
server.get('/redux',(req,res)=>{
res.render('./views/index.tsx')
})
视图文件
import React = require('react')
console.log('express-tsx' as any)
export type Props = { word:string }
export const props = require('?props');import '?props';
export const View:React.StatelessComponent<Props> = (props)=>
<div>
hello {props.word}
</div>
示例运行
实现流程