React 组件化思想受到愈来愈多开发者的关注,组件化思想帮助开发者将页面解耦成一个一个组件,代码更加模块化, 更易扩展。而目前流行的后端模板引擎如 ejs, swig, jade, art 共同的问题是:css
针对以上痛点,笔者基于 React 造出了 noox 这样一个工具,专一于后端模板的解析,让模板解析更加简单,易用。node
npm install noox
复制代码
首先建立组件目录和增长模板文件git
mkdir components && cd components
vi Head.jsx
复制代码
Head.jsx 内容以下:github
<head>
<title>{title}</title>
<meta name="description" content={props.description} />
<link rel="stylesheet" href="./css/style.css" />
</head>
复制代码
const noox = require('noox');
const nx = new noox(path.resolve(__dirname, './components'), {title: 'noox'});
let output = nx.render('Head', {description: 'hello, noox.'})
复制代码
<head>
<title>noox</title>
<meta name="description" content="hello, noox." />
<link rel="stylesheet" href="./css/style.css" />
</head>
复制代码
Noox 在 React 的 Jsx 的基础上,简化了组件引用和建立,假设建立一个目录结构以下:npm
components/
Header.jsx
Body.jsx
Layout.jsx
复制代码
运行以下 nodejs 的代码:后端
nx = new noox(path.resolve(__dirname, './components'))
复制代码
将会建立三个组件:api
而后经过 nx.render 渲染bash
nx.render('Body', props)
复制代码
感兴趣的能够 star 关注下,共同探讨模块化
Github: noox工具
另外推广下咱们团队的项目 YApi