gulp使用备忘
1.bower的package.json中增加依赖:
"devDependencies": { "bower": "^1.7.7", "gulp": "^3.9.0", "gulp-concat": "^2.6.0", "gulp-htmlmin": "^2.0.0", "gulp-jshint": "^2.0.0", "gulp-minify-css": "^1.2.3", "gulp-rename": "^1.2.2", "gulp-uglify": "^1.5.1" }
2.安装gulp
npm install --global gulp
3.配置gulpfile.js
var gulp = require('gulp'), minifyhtml=require('gulp-htmlmin'), minifycss = require('gulp-minify-css'), concat = require('gulp-concat'), uglify = require('gulp-uglify'), rename = require('gulp-rename'), jshint = require('gulp-jshint'); gulp.task('minifycss', function () { return gulp.src([ 'app/css/xxx.css', 'app/css/xxx.css', 'app/css/xxx.css' ]) .pipe(concat('main.css')) .pipe(gulp.dest('app')) .pipe(rename({suffix: '.min'})) .pipe(minifycss()) .pipe(gulp.dest('app')); }); gulp.task('minifyjs', function () { return gulp.src([ 'app/js/xxx.js', 'app/js/xxx.js', 'app/js/xxx.js' ]) .pipe(concat('main.js')) .pipe(gulp.dest('app')) .pipe(rename({suffix: '.min'})) .pipe(uglify()) .pipe(gulp.dest('app')); }); gulp.task('minifyhtml', function() { var options = { removeComments: true,//清除HTML注释 collapseWhitespace: true,//压缩HTML collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input /> removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input /> removeScriptTypeAttributes: true,//删除<script>的type="text/javascript" removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css" minifyJS: true,//压缩页面JS minifyCSS: true//压缩页面CSS }; return gulp.src('app/*.html') .pipe(minifyhtml(options)) .pipe(gulp.dest('app')); }); gulp.task('default', function () { gulp.start('minifycss', 'minifyjs','minifyhtml'); });
4.运行gulp
相关推荐
星辰的笔记 2020-07-04
zhongweinan 2020-06-10
jiangfulai 2020-04-18
hlihaihong 2020-01-13
kaosini 2020-01-12
kaosini 2020-01-12
FranksTD 2019-12-19
hlihaihong 2019-12-15
hlihaihong 2019-12-14
我有一只小松鼠 2019-12-14
FranksTD 2019-12-13
SeekerTime 2019-11-17
yuetingzhuying 2015-10-17
福叔 2019-09-06
kaosini 2019-09-06
RainyX 2019-07-01
hlihaihong 2019-07-01
idnochinese 2019-07-01
UndefineOrNull 2019-07-01