# normae
**Repository Path**: firebata/normae
## Basic Information
- **Project Name**: normae
- **Description**: front-end integrated solution of Lagou based on fis3
- **Primary Language**: JavaScript
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2017-06-07
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# normae
normae是基于[fis3](http://fis.baidu.com/fis3/index.html)的拉勾网前端解决方案
* 后端为Java+Velocity
* 采用less作为css处理器
* 采用amd模块化开发方案
* 采用bower管理第三方依赖
阅读本文档前,建议先阅读[fis3的文档](http://fis.baidu.com/fis3/docs/beginning/intro.html),很多涉及到fis3的内容都没有提及,请查看相应的文档。
## 目录规范
```
site //能独立提供服务,具有单独二级域名的产品线
├ common //通用子系统
| ├ components //组件,业务逻辑无关
| | ├ popoup
| | | | ├ popoup.js
| | | | └ popoup.less
| ├ static //非组件模块资源目录,包括模板页面引用的静态资源(favicon.ico)
| ├ widgets //模块,业务逻辑相关
| | ├ header
| | | | ├ header.html
| | | | ├ header.js
| | | | └ header.less
├ dep //第三方依赖
| ├ jquery
| | └ jquery.js
| ├ esl
| | └ esl.js
├ test //测试数据
| ├ common //所有模版共用的模拟数据,主要放置velocity tool相关的方法
| | └ common.js
| ├ ajax //模拟ajax请求返回的数据
| | └ test.json
├ sub //子系统,具有较清晰业务逻辑关系的功能业务集合
| ├ page //具有独立URL的输出内容
| | ├ index
| | | | ├ index.html //velocity模版
| | | | ├ index.html.js //页面对应的mock数据
| | | | ├ index.less
| | | | └ index.js
| ├ static
| ├ modules
| | ├ content
| | | | ├ img
| | | | ├ tpl //放置模块的前端模版
| | | | | └ content.tpl
| | | | ├ content.html
| | | | ├ content.js
| | | | └ content.less
| ├ fis-conf.js //子系统的fis配置文件
| ├ server-conf.js //子系统的url模拟转发配置文件
├ .bowerrc //bower配置文件
├ bower.json //bower package文件
├ fis-conf.js //fis配置文件
├ server.conf //本地url模拟转发配置文件
```
## 使用
### 全局安装normae
``` shell
$ npm install normae -g
```
### 全局安装bower
``` shell
$ npm install bower -g
```
### normae内置了3种release模式
* 默认的dev模式,用于本地调试,会编译velocity,模拟转发url。
``` shell
$ normae release
```
* qa模式,用于测试环境测试,会添加md5戳,打包,合成精灵图。
``` shell
$ normae release qa
```
* prod模式,用于生产环境上线,会添加md5戳,打包,合成精灵图,压缩。
``` shell
$ normae release prod
```
具体配置请参考[这里](https://github.com/vicerwang/normae/blob/master/index.js)。
normae的三种release方式只提供了一些基本的匹配处理规则,如果想添加适合本项目的特殊规则,如具体的打包规则等,请在项目根目录下的fis-conf.js文件中添加规则来扩展或覆盖基本的规则。
### 按子系统release
随着子系统的增加,给我们的日常开发带来了以下两个问题
1. 整个系统releae,时间越来越长,自动刷新功能总是延迟很多
2. `fis-conf.js`,`server.conf`配置文件内容越来越多,变得难以维护
因此,normae在v0.1.0将release的粒度改到子系统的层级,相应地需要在子系统目录下添加fis-conf.js以及server.conf来配置release规则和url转发规则,而根目录下的fis-conf.js以及server.conf则放置一些common的配置。通过修改根目录下的fis-conf.js文件中的releaseMods变量,来release所有子系统或者指定的子系统:
``` javascript
var releaseMods = [ 'dashboard' ];
// var releaseMods = 'all';
var root = fis.project.getProjectPath();
var confs = fis.util.find(root, '/**/fis-conf.js');
var path = require('path');
var mods = [];
confs.forEach(function(conf) {
var mod = path.dirname(path.relative(root, conf));
mod !== '.' && mods.push(mod);
});
mods.forEach(function(mod) {
if (releaseMods === 'all') {
require('./' + mod + '/fis-conf');
delete require.cache['./' + mod + '/fis-conf'];
} else if (releaseMods.indexOf(mod) === -1) {
fis.match('/' + mod + '/**/*', {
release: false
});
} else {
require('./' + mod + '/fis-conf');
delete require.cache['./' + mod + '/fis-conf'];
}
});
```
需要注意以下几点:
* 如果修改了子系统间共同依赖的资源,请release所有的子系统
* 通过`-wL`参数开启监听改动自动刷新功能后,即使修改了子系统下的fis-conf.js文件,也不会被监听到,请重新输入`normae release -wL`release
### 本地调试
``` shell
$ normae server start
```
其他命令以及参数请参考[fis相关文档](http://fis.baidu.com/fis3/docs/beginning/debug.html#%E5%90%AF%E5%8A%A8)。
* #### 模拟转发url
normae使用fis内置server默认的node server,同时开启模拟转发url功能,需要在项目根目录添加server.conf文件。
文件内容参考如下:
``` shell
rewrite ^\/$ /template/sub/page/index/index.html
rewrite /test.json /test/ajax/test.json
```
配置文件说明:
* 配置文件每一行为一条规则。
* 规则格式为:匹配类型 (空格) 匹配url正则或url (空格) 命中后的目的文件url。
* 匹配类型包括rewrite和redirect。
* rewrite:匹配规则后转发到一个文件,同时url修改为访问文件的url。
* redirect:匹配规则后重定向到另一个url。
* #### 编译velocity模版
借助fis-postprocessor-velocity插件,实现在开发阶段编译velocity模版。如果page文件夹下存在独立页面的velocity模版index.html,则需要在同级目录添加mock数据文件index.html.js。
index.html
``` html