4 Star 1 Fork 0

ec_huyinghuan/slow-cli

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

SLOW

前端开发, 构建工具。

安装

npm install -g slow-cli

##使用

在项目根目录下运行

slow init

进行初始化。 完成后会有相关配置 在.slow文件夹下生成。 可以根据自己需要配置。当然,可以使用默认配置

之后运行

slow start

就可以跑起来了。 默认端口是3000.

配置

配置请参考 src/sample/.slow/config.coffee 配置

Shell 命令

slow init

初始化slow 项目根目录运行一次即可

slow build

将整个工程 进行构建。 构建完成后,不依赖slow, 可以通过nginx配置后,直接跑起来。当然, 如果你配置过 路径代理, 那么nginx需要进行相应配置才行。

slow

将项目 运行在http 服务内(slow 自带), 可以通过 -p 指定端口, 通过 -dev 指定运行环境

指令

在hbs 文件中支持 include 和import 指令。

include

将其他文件包含进来。 例如 a.html

<div>hello world</div>

b.hbs

<body>
{{include "a.html"}}
</body>

编译后(在浏览器访问 localhost:xxx/xx/b.html) 得到的结果是

<body>
  <div>hello world</div>
</body>

import

import指令主要用于引用 css 和js 文件

例如

<head>
{{import "css/*"}}
</head>

得到的结果是将文件夹css下的所有文件全部引入到head标签中。 不包括子文件夹。

这个指令支持css和js文件资源的自动引入。 包括 less 和 coffee

proxy代理

解决跨域问题。 在前后端分离的趋势下, 前段 不依赖后台服务器 进行api访问。

如果直接访问api 会造成 跨域 限制。 通过proxy 配置,跨域解决这个问题, 支持多路径 代理。 具体参考配置文件src/sample/.slow/config.coffee 的proxy相关设置。

其他

支持 coffee,less原生编译, 也就是如果你是通过 coffee写的文件 ,按照 .js文件的方法引用即可

如: a.coffee 在引用时 写成<script src="xx/a.js"></script>即可。less同理。

运用

芒果tv内部某些属于我的任务中使用。

Bug 与 Suggestion

可以提issue 或者 pr

扩展

SLOW 支持一定程度上的扩展。比如中间件方式等。只需要在src/lib/middleware 下添加服务相关格式的函数即可自动添加到运行环境中。 比如 添加支持Sass支持。只需在该目录下添加个文件如 xxx-sass.coffee (如果你不用coffee那么,在lib/middleware下建立js文件即可)

_async = require 'async'

isSassFile = (path)->
   if ....
      return true

   else
      return false

module.exports = (req, resp, next)->
  pathName = req.client.pathName

  if not isSassFile(pathName) #如果pathName 不是 sass文件类型 #伪代码
      return next() #当请求路径不符合你的拦截请求的话,运行next()  将请求交给下个 拦截器

  ....
  err = null
  #编译 sass文件
  try
    result = _sass.compile .....
  catch e
    err = e
  ...
  return resp.throwsServerError() if err
  resp.sendContent result, "text/css"

如果你使用的是coffee,那么需要目录下编译一次 (不是每个人都用coffee,编译好后,会自动生成到lib相应目录下,方便其他人使用)

grunt coffee

例外还支持一些其他的扩展方式,如果有需要,可以在issue中提出,我会回复。

未来

  1. 将集成我的另外一个库slow-data 进行api 数据模拟, 避免 后台开发延期导致前端 无法获取数据而造成的 任务进程停滞不前。

  2. 完成具体的插件机制, 增加更多可选插件。 比如文件合成等等

#SLOW [TOC] # What is SLOW? >SLOW is a web framework that help web developer focus on html,css, >javascript and don't need care for server. You can develop web with LESS >and Coffee and don't need compile them, SLOW will do them automatically. >So you just need spend less time in work, coding slowly and thinking in coding, >enjoy coding. Coding is not just for finish your work. #How to install? `slow` need be installed as global. `sudo npm install -g slow-cli` # Getting Start There is a slow project sample in "slow-cli/sample". ## Init a slow project ```shell #In the project directory, get a slow project by runing slow init ``` ##Take over and starup a http server ```shell #In the project directory run. slow start #And then open the browser with http://localhost:3000 ``` ## Enjoy your develop! Now, you can enjoy coding with handlebar, coffeescript, less. don't need use grunt or gulp compile your project. #Develop with slow There are all configs for slow, every fields will be described in the next section. this is develop config:(you can find it in `.slow/config.js`) ``` { "environment": "develop", "develop": { "port": 3000, "base": { "index": "index.html", "cache-time": 60 * 60 * 24 * 7, "gzip": true, "isWatchFile": true, "showResponseTime": true }, "proxy": { "path": /^\/api/, "options": { "target": "http://localhost:8000" } }, "error": { "403": '' }, "log": { "log2console": true, "timestamp": false, "levelShow": true, "lineInfo": false, "log2file": false } } ``` This is product config, you can find it in `.slow/product-config.js` it's same with develop config. ``` { "port": 3000, "base": { "index": "index.html", "cache-time": 60 * 60 * 24 * 7, "gzip": true, "isWatchFile": true, "showResponseTime": false }, "proxy": false, "error": { "403": '' } } ``` This is build config. it be used when you run `slow build` you can modify in .slow/build.js ``` { "target": "build", "mincss": { "include": /.+\.(less|css)$/, "ignore": [/.+(\.min\.css)$/], "options": {} }, "minjs": { "include": /.+\.(js|coffee)$/, "ignore": [/.+(\.min\.js)$/], "options": { "mangle": false, "compress": {} } }, "hbsCompile": { "include": /.+(\.hbs)$/ }, "coffeeCompile": /.+(.coffee)$/, "lessCompile": /.+(.less)$/, "ignore": [/^(\.slow).+/, /.*(\.gitignore)$/] } ``` ## Set work environment When we are developing a web project, we are in develop environment, so, at the first, you can setting slow work environment to be "develop" like this: ```js module.export = { "environment": "develop", //... } ``` There just are two values for `environment` option, `develop` and `product`. the default setting is "develop". the environment option tell `slow` which config should be load when it is working. ## Config develop environment After set the work environment be `develop`, Now we can config the develop environment. There already has some default config option at ".slow/config.js". You define them by yourself in "develop" field. ### port the port that be `slow`used.default is `3000`. ### base #### index #### cache-time #### gzip #### isWatchFile #### showResponseTime ### proxy #### path #### options ### error ### log ## Config product enviroment ## Config build enviroment ###target ###mincss ####include ####ignore ####options ###minjs ###hbscompile ###cofeeCompile ###lessComplie ###ignore #HTML derective ## include ## import ## watch_file #Slow extensions #Shell ##slow init ##slow build ##slow update ##slow start ### slow -p [port] ### slow -env [develop | product] # Feature 1. support less 2. support coffee-script 3. support handlebar - support import directive - support include directive 4. support http-proxy 5. support file watch 6. support gzip # LICENCE MIT ## History v0.1.9beta3 1. fix bug that can not build project less. 2. modify the start way from ```slow``` to ```slow start```. Avoid conflict with other shell commander v0.1.9beta1 1. catch the error when compile coffeescript and hbs file. avoid the ```slow``` crash. v0.1.8beta6 1. support proxy multipath v0.1.8beta3 1. update command ```init``` v0.1.8-beta1 1. add shell ```slow build``` package slow project to a pure html project. Don't need depend ```slow``` >slow build support: >1. autocompile coffee, less, handlebar >2. compress js, css to min file v0.1.7 1. fix a bug that slow-cli crash when proxy config don't exists 2. add log config in config.js. more config see [log4slow](http://github.com/huyinghuan/log4slow) 3. add build project optional.(doing. it will publish in v0.1.8) v0.1.6 1. fix a bug about issue #1 v0.1.4 1. exchange ```import``` and ```include``` function v0.1.3 1. fix some bugs. v0.1.1 1. update README.md and fix bug can not install v0.1.0 1. finish basic function

简介

前台开发,构建工具 展开 收起
CoffeeScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
CoffeeScript
1
https://gitee.com/huyinghuan/slow-cli.git
git@gitee.com:huyinghuan/slow-cli.git
huyinghuan
slow-cli
slow-cli
master

搜索帮助

Cb406eda 1850385 E526c682 1850385