【工具】gulp和JsonSever结合模拟数据
来源:互联网 发布:死亡之舞 卡罗 知乎 编辑:程序博客网 时间:2024/06/16 11:31
前言
本来呢?研究这个课题的目的是让gulp自动返回模拟的后台数据,但是还没有做出来,仅仅出来个中间效果,告别F5时代的HTML页。
gulpfile.js
'use strict';var gulp = require('gulp'), less = require('gulp-less'), connect = require('gulp-connect'), port = 5000;//访问的端口var rename = require('gulp-rename');var plumber = require('gulp-plumber'); // 错误处理插件var notify = require('gulp-notify'); // 消息插件var autoprefixer = require('gulp-autoprefixer'); // 自动添加前缀var minifycss = require('gulp-minify-css');var proxy = require('http-proxy-middleware');gulp.task('server',function(){ connect.server({ root:[__dirname], port:port, livereload:true, middleware:function(connect, opt){ return [ proxy('/api', {// configure proxy middleware // context: '/' will proxy all requests // use: '/api' to proxy request when path starts with '/api' target: 'http://localhost:3000', changeOrigin:true // for vhosted sites, changes host header to match to target's host }) ]; } });});gulp.task('reload',function(){ gulp.src(['./index.html', './less/style.less']) .pipe(connect.reload());});gulp.task('default',['server'],function(){ gulp.watch(['./index.html'],['reload']);});
HTML页
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <script src="http://apps.bdimg.com/libs/zepto/1.1.4/zepto.min.js"></script></head><body><h1>gulp</h1><script> // $.get('api/profile',function(re){ // console.log(re); // }) $.post("api/posts",{suggest:'xx'},function(re){ console.log(re); });</script></body></html>
db.json
{ "posts": [ { "id": 1, "title": "json-server", "author": "typicode" } ], "comments": [ { "id": 1, "body": "some comment", "postId": 1 } ], "profile": { "name": "typicode" }}
效果
HTML页
修改保存后
直接保存,无需F5刷新页面即可将结果显示出来。
总结
虽然真正想要的结果没有出来,但在研究的过程中还是收获了很多东西的,相比之前保存页面代码后,还需要在前台刷新才能出来结果,现在能直观的展现出我们的修改,在效率与体验上也是相当有进步的。
0 0
- 【工具】gulp和JsonSever结合模拟数据
- 前端数据模拟服务器 gulp-connect 和 JSON Server
- webpack和gulp结合使用
- 前端工具webpack和gulp
- gulp常用插件和工具
- gulp工具
- 前端工具gulp的用途和使用方法
- 前端 构建工具 Gulp和 Grunt、npm
- gulp结合seajs开发
- Typescript结合gulp开发
- 数据模拟工具
- MockJs结合json-server模拟后台数据
- 有线和无线结合的模型模拟
- Gulp和webpack的区别,是一种工具吗?
- gulp自动化构建工具快速入门和实战
- gulp和bower工具的环境搭建以及使用介绍
- 前端自动化工具里面gulp和fis,有哪些优缺点?
- 前段自动化工具gulp安装、使用和调试
- 感谢csdn提供的c-ide环境
- 如何通过Android Studio写一个库
- VC生成静态库release版比debug版库文件尺寸更大的原因
- 消息队列学习笔记
- Android 向右滑动销毁(finish)Activity, 随着手势的滑动而滑动的效果
- 【工具】gulp和JsonSever结合模拟数据
- LBP特征
- JS的常用正则表达式 验证密码用户名等
- 260. Single Number III
- 利用Wireshark抓取WebSocket数据包
- 布局嵌入tablayout无法点击的问题
- 详解callee和caller, apply()和call()的用法 — 第5.5.4节
- 浅谈mvc
- 数组指针与指针数组