使用gulp构建工具
之前一个demo中用的是grunt,照着grunt用到的插件找了下gulp的,总体使用还算顺畅,说实话并不觉得学习成本有降低什么的,差不多。不过也遇到一些问题:
1、gulp.dest()输出目录需要用"./"而不能"/"
2、gulp的jshint有些规则检测不到,而grunt却检测到了,可以用"asi": true测试下。(据说现在大家都用eslint代替jslint,看了下有eslint180条左右的规则,吓cry了好么。)
3、gulp任务有些执行完毕后不会有消息提示,而grunt的插件就友好很多。
gulp.task('uglify', ['jshint'], function() {//...}
package.json
{
"name": "vip.uc108",
"version": "0.1.0",
"devDependencies": {
"del": "^1.2.0",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-csscomb": "^3.0.6",
"gulp-eslint": "^1.0.0",
"gulp-file-include": "^0.13.7",
"gulp-imagemin": "^2.3.0",
"gulp-jshint": "^1.11.2",
"gulp-livereload": "^3.8.0",
"gulp-minify-css": "^1.2.0",
"gulp-notify": "^2.2.0",
"gulp-rename": "^1.2.2",
"gulp-ruby-sass": "^1.0.5",
"gulp-uglify": "^1.2.0"
}
}
gulpFile.js
var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
var csscomb = require('gulp-csscomb');
var fileinclude = require('gulp-file-include');
var imagemin = require('gulp-imagemin');
var jshint = require('gulp-jshint');
var livereload = require('gulp-livereload');
var cssmin = require('gulp-minify-css');
var notify = require('gulp-notify');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
gulp.task('sass', function() {
return sass('./static/introduce/scss', {
style: "compressed"
})
.on('error', function(err) {
console.error('Error!', err.message);
}).pipe(gulp.dest('./static/introduce/css'))
.pipe(livereload({
start: true
}));
});
gulp.task('css', function() {
return gulp.src(['./static/activity/**/*.css', '!./static/activity/**/*min.css'])
.pipe(csscomb()).
pipe(cssmin()).
pipe(rename(function(path) {
path.basename += ".min";
}))
.pipe(gulp.dest('./static/activity'))
.pipe(livereload({
start: true
}));
});
gulp.task('image', function() {
gulp.src('static/activity/index/img/*')
.pipe(imagemin())
.pipe(gulp.dest('./static/activity/index/img'));
});
gulp.task('jshint', function() {
return gulp.src(['./static/activity/**/*.js', '!./static/activity/**/*.min.js'])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'));
});
gulp.task('uglify', ['jshint'], function() {
return gulp.src(['./static/activity/**/*.js', '!./static/activity/**/*.min.js'])
.pipe(uglify({
ext: ".min.js"
}))
.pipe(rename(function(path) {
path.basename += ".min";
}))
.pipe(gulp.dest('./static/activity/'));
})
gulp.task('fileinclude', function() {
return gulp.src('src/html/**/*.html').
pipe(fileinclude({
prefix: '@@',
basepath: '@file'
})).pipe(gulp.dest('./view'));
});
gulp.task('watch', function() {
gulp.watch(['./static/activity/**/*.js', '!./static/activity/**/*.min.js'], ['uglify']);
});
gulp.task('default', ['image', 'fileinclude'], function() {
gulp.src('package.json').pipe(notify("default finished"));
});
关于gulp插件,有空再试下这些~~
gulp-rev
gulp-concat
gulp-sourcemaps
gulp-connect
使用gulp构建工具的更多相关文章
- Grunt和Gulp构建工具在Visual Studio 2015中的高效的应用
Grunt和Gulp构建工具在Visual Studio 2015中的高效的应用 Grunt和Gulp是Javascript世界里的用来做自动压缩.Typescript编译.代码质量lint工具.cs ...
- [翻译]在gulp构建工具中使用PostCSS
前言 PostCSS已经在一段时间内迅速普及,如果你还不知道PostCSS或还没有使用它,我建议你看一下之前的一篇介绍文章<PostCSS简介>,其中介绍了使用PostCSS的基本方法,包 ...
- ASP.NET5之客户端开发:Grunt和Gulp构建工具在Visual Studio 2015中的高效的应用
Grunt和Gulp是Javascript世界里的用来做自动压缩.Typescript编译.代码质量lint工具.css预处理器的构建工具,它帮助开发者处理客户端开发中的一些烦操重复性的工作.Grun ...
- gulp构建工具学习汇总
前端脚手架____gulp配置文件------- https://pan.baidu.com/s/1eSs7COy 1:有了package.json 直接 npm install自动下载相应的npm包 ...
- gulp 构建工具
1. gulp 的简介 gulp是前端开发过程中对代码进行构建的工具,是自动化项目的构建利器:她不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成:使用她,我们不仅可以 ...
- gulp构建工具的安装
第一步:node.js安装 在gulp安装之前,本机需要node环境.访问http://nodejs.org,然后点击大大的绿色的install按钮,下载完成后直接运行程序.npm会随着安装包一起安装 ...
- express+gulp构建项目(二)启动项目和主文件
这一次整理的内容是项目主文件和如何启动项目. 启动项目 通过nodejs官网的例子https://nodejs.org/docs/latest-v4.x/doc/api/synopsis.html我们 ...
- 构建工具--glup如何压缩,丑化代码
目录 为什么使用 实现 为什么使用 最近在迭代公司的项目,发现项目有如下缺点: 代码没有压缩,js文件,内存大,放在服务器上占空间: 源代码没有混淆或者丑化处理,本公司的程序员写出来的代码和高质量逻辑 ...
- 前端打包构建工具gulp快速入门
因为之前一直有人给我推荐gulp,说他这里好哪里好的.实际上对我来说够用就行.grunt熟悉以后实际上他的配置也不难,说到效率的话确实是个问题,尤其项目大了以后,目前位置遇到的项目都还可以忍受.不过不 ...
随机推荐
- bzoj 3083 遥远的国度 —— 树链剖分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3083 换根后路径还是不变,子树分类讨论一下,树剖后线段树维护即可. 代码如下: #inclu ...
- bzoj 1101 Zap —— 莫比乌斯反演
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 直接莫比乌斯反演. 代码如下: #include<cstdio> #inc ...
- POJ2785(upper_bound)
#include"cstdio" #include"algorithm" using namespace std; ; int A[MAXN],B[MAXN], ...
- eclipse如何集成tomcat插件
刚在Eclipse官方网站下载的Eclipse,需要自己手动安装tomcat插件才能配置tomcat服务器.网上好多安装方法,这里我就不厌其烦的再写一遍,边安装边截图讲解下安装方法. 首先你要去下载E ...
- Python-实现socket简单地连续发数据
只需用while条件判断来实现 服务器端 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import socket serv ...
- 面试题: redis面试题 有用 redis详细
redis面试题目总结 2017-08-25 09:31:02 0个评论 来源:Java仗剑走天涯 收藏 我要投稿 (1)什么是redis? Redis 是一个基于内存的高 ...
- HTML基础:
HTML是英文HyperText Markup Language的缩写,即超级文本标记语言,是用于描述网页文档的一种标记语言.HTMl是目前网络上应用最为广泛的语言,也是构成网页文档的主要语言.HTM ...
- Linux 静态库(.a)转换为动态库(.so)
Linux 静态库转换为动态库 参考 http://blog.csdn.net/moxuansheng/article/details/5812410 首先将.a文件转为.so文件是可以实现的 原因是 ...
- e.key && e.which && e.keyCode
官方推荐用e.key来描述状态码,其他两种属性可能会在未来被废弃. 且key,keyCode和which 为只读属性 但是会有浏览器兼容性的问题,可以采用如下代码: let key = ''; ...
- mobile web页面调试方法
此文已由作者张含会授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 开发过程问题排查 Chrome Emulation关键词:使用方便 模拟各种设备尺寸.像素比.自定义user ...