Giter Site home page Giter Site logo

gulp-turbo's Introduction

gulp-Turbo (译:涡轮增压器,为前端开发联调加速)

前端脚手架-v1

  1. 快速构建前端项目
  2. 提供易于开发、调试的开发联调环境,支持预编译语言(jade,stylus,coffee)
  3. 提供基于requirejs的实时打包服务。
  4. 提供http server, 支持mock接口数据功能。
  5. 提供json文件自动校验
  6. 提供80端口代理、转发功能
  7. 提供透明代理(即:线下不存在的资源,直接抓取线上)
  8. 提供代理服务(即:htpp代理服务,支持抓包和mapping本地文件,可以用来调试移动端)
  9. 提供获取svn的change list工具, 以便用于填写上线单

安装(依赖node.js,npm)

  #全局gulp包
  npm i gulp -g

  #本地gulp包
  npm i gulp --save

  #安装gulp-turbo
  npm i gulp-turbo --save

创建项目

1. 初始化npm项目、安装依赖

npm init
npm i require-dir --save

2. 创建gulpfile.js

var gulp, porjectConf, requireDir, turbo;
gulp              = require('gulp');
requireDir        = require('require-dir');
turbo             = require('gulp-turbo');
porjectConf       = require('./porject-conf.json');
global.globalGulp = gulp;
global.pkg        = porjectConf;
requireDir(turbo.dir);

gulp.task('dev', ['jsonlint', 'setDev', 'compile', 'proxy', 'server', 'watch']);
gulp.task('dist', ['setDist', 'jade', 'stylus', 'rMin', 'cpVender', 'cpImg','server', 'watch']);
gulp.task('default', ['dev']);

3.配置项目(创建project-conf.json)

注意:json文件里面不能有注释

{
  //路由路径:比如将项目访问根目录127.0.0.1改为虚拟路径http://127.0.0.1/tech-bs
  "routerPath": "/tech-bs",

  //项目文件夹根目录名称
  "approot": "app",

  //默认开发模式
  "distMode": "dev",

  //静态资源域名。项目中的静态资源都是以带有域名的绝对路径引用的,将会用到这个配置。
  "domain": "//xxx.bbb.com",

  //配置透明代理时需要用到这个。即:线下没有的文件,将会在这个域名为根去获取内容,要求此域名跟domain指向的静态资源池相同
  "vhost": "http://xxx.aaa.com.cn",

  //自动刷新浏览器。用于调试 true是开启,将会在页面注入一个js用来做实时通讯。
  "forceLivereload": true,

  //默认端口
  "httpProt": 80,

  //反向代理,用于共享 httpProt 端口
  "serverProxies": [{

    //如果用户访问这个路径,如 http://127.0.0.1/tech-bs/abc, 相当与访问 target设置的http路径,但还是走httpProt端口
    "source": "/tech-bs/abc",
    "target": "http://127.0.0.1:8080/tech-bs/abc",
    "options": {
      //请求头
      "headers": {
        "ABC_HEADER": "abc"
      }
    }
  }, {
    "source": "/tech-bs/aaa",
    "target": "http://127.0.0.1:8081/tech-bs/aaa"
  }],

  // 代理服务器端口。 通常用于调试移动端,抓包,替换请求. 类似fiddler或者charlse
  "proxyProt": 8989,

  //代理规则(支持正则,可以设置多个规则)
  "proxyRule": [{

    //替换规则
    "pattern": "xxx.b.com/skyfire/ssu/editBefore1",

    //用于响应的文件
    "responder": "/Users/kings/didi/prod/fe-scaffold-v1/app/dev/html/page1.html"
  }]
}

4.运行(创建project-conf.json)

注意:mac监听1024以下端口通常需要 sudo gulp) 访问路径为 http://127.0.0.1/ +routerPath 例:http://127.0.0.1/tech-bs 启动服务后,将持续监听src下的目录文件变化,自动编译。 gulp启动服务后,命令窗口不能关闭。想要实现关闭命令行服务继续运行,可以执行 nohup gulp &&

  #创建文件夹
  gulp init

  #启动服务
  gulp

运行example

    git clone [email protected]:ian000/gulp-turbo.git
    cd gulp-turbo
    npm i
    cd example
    npm i
    gulp (注意:mac监听1024以下端口通常需要 sudo gulp)

快速构建前端项目目录

gulp init

提供易于开发、调试的开发联调环境(支持预编译语言jade,stylus,coffee)

运行默认环境 dev

gulp

提供基于requirejs的实时打包服务。

运行编译环境 dist, 用于上线

gulp dist

提供http server, 支持mock接口数据功能。


按照后端接口,在mock目录下按层级创建json文件.详细请参考现存的mock数据路径。

提供80端口代理、转发功能

 在package.json文件中设置转发规则。
 e.g :

 "serverProxies":[
              {
                "source": "/tech-bs/abc",
                "target": "http://127.0.0.1:8080/tech-bs/abc",
                "options": {
                  "headers": {
                    "ABC_HEADER": "abc"
                    }
                  }
              },
              {
                "source": "/tech-bs/aaa",
                "target": "http://127.0.0.1:8081/tech-bs/aaa"
              }
            ]
  当访问 http://127.0.0.1/tech-bs/abc 时,会命中第一条代理规则,转发到 8080端口对应的路径。
  这对于并行开发多个项目很有用。

问题列表

  1. - 使用turbo,前后端如何联调页面?
  2. - 如何设置浏览器代理?
  3. - 手动安装chrome代理插件:SwitchyOmega

change log

[12.03] -【里程碑】将脚手架包装成npm组件
[12.03] - 加入json文件校验
[12.03] - 为解决gulpfile.coffe以后的维护问题,拆分gulpfile.coffe到gulp-tasks文件夹
[12.03] - 压缩css、js时,添加处理文件的log信息输出
[12.02] - 在gulp dist之前不需要先执行gulp dev了
[11.16] - svnChanges任务修改,过滤掉文件夹和删除的变更记录
[11.12] - 提供80端口代理、转发功能
[11.12] - 新增svnChanges任务,获取svn log中的change list, 以便用于填写上线单
[11.10] - 在dist模式下,增加sourcemaps支持
[11.09] - 抽离配置文件到package.json中
[11.06] - 新增图片文件夹
[11.06] - 支持透明代理
[11.06] - 支持代理
[11.05] - 修复dist模式
[11.04] - 新增page_$config.json
[11.04] - 自动配置页面内的wwwroot

TODOS

  1. 将资源合并,构建组件化机制。
  2. dist文件夹内文件统一添加版本号问题
  3. 服务挂载

Contributors

赵新
王江伟

gulp-turbo's People

Contributors

ian000 avatar

Watchers

James Cloos avatar coding笨妈 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.