Skip to content

Commit

Permalink
图片压缩
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangrenyang-t510 committed Dec 22, 2015
1 parent c8af502 commit a3b3650
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 45 deletions.
Binary file added app/imgs/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions app/js/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/**
* Created by Administrator on 2015-12-22.
*/
//main
console.log('main');
2 changes: 2 additions & 0 deletions app/js/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//page
console.log('page');
5 changes: 2 additions & 3 deletions app/js/tmp.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/**
* Created by Administrator on 2015-12-22.
*/
//tmp
console.log('tmp');
1 change: 1 addition & 0 deletions app/less/index.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
body {
color: red;
width: 400px;
}
h2 {
color: red;
Expand Down
1 change: 1 addition & 0 deletions app/less/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

body {
color: @xxx;
width:400px;
}
h2 {
color: @xxx;
Expand Down
6 changes: 0 additions & 6 deletions dist/css/index.css

This file was deleted.

11 changes: 0 additions & 11 deletions dist/index.html

This file was deleted.

27 changes: 7 additions & 20 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
var gulp = require('gulp');
var less = require('gulp-less');
var connect = require('gulp-connect');
var rename = require('gulp-rename');
var imagemin = require('gulp-imagemin');

gulp.task('copyhtml',function(){
gulp.src('app/index.html').pipe(gulp.dest('dist')).pipe(connect.reload());
gulp.task('copy-images',function(){
return gulp.src('app/imgs/**/*.{jpg,png}',{base:'app'})
.pipe(imagemin())
.pipe(gulp.dest('dist'));
});

gulp.task('less',function(){
gulp.src('app/less/index.less').
pipe(less()).pipe(gulp.dest('dist/css')).pipe(connect.reload());
});

gulp.task('server',function(){
connect.server({
root:'dist',//服务器的根目录
port:8080 //服务器的地址,没有此配置项默认也是 8080
, livereload: true //自动刷新
});
gulp.watch('app/index.html',['copyhtml']);
gulp.watch('app/less/index.less',['less']);
});
//运行此任务的时候会在8080上启动服务器,
gulp.task('default',['copyhtml','less','server']);
gulp.task('default',['copy-images']);
14 changes: 14 additions & 0 deletions history/concatuglify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var gulp = require('gulp');
var concat = require('gulp-concat');//把多个文件合并成一个文件
var uglify = require('gulp-uglify')
var rename = require('gulp-rename');
gulp.task('uglify',function(){
return gulp.src(['app/js/*.js','!app/js/*tmp.js'])
.pipe(concat('app.js'))
.pipe(gulp.dest('dist/js'))
.pipe(uglify())
.pipe(rename('app.min.js'))
.pipe(gulp.dest('dist/js'));
});

gulp.task('default',['uglify']);
14 changes: 14 additions & 0 deletions history/cssmin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var gulp = require('gulp');
var less = require('gulp-less');
var minify = require('gulp-minify-css');
var rename = require('gulp-rename');
gulp.task('minify',function(){
return gulp.src('app/less/index.less')
.pipe(less())
.pipe(gulp.dest('dist/css'))
.pipe(minify())
.pipe(rename('index.min.css'))
.pipe(gulp.dest('dist/css'));
});

gulp.task('default',['less']);
8 changes: 8 additions & 0 deletions history/minifyhtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var gulp = require('gulp'),
minifyHtml = require("gulp-minify-html");

gulp.task('minify-html', function () {
gulp.src('app/*.html') // 要压缩的html文件
.pipe(minifyHtml()) //压缩
.pipe(gulp.dest('dist/html'));
});
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
"description": "",
"main": "index.js",
"dependencies": {
"gulp": "^3.9.0"
"gulp": "^3.9.0",
"gulp-imagemin": "^2.4.0",
"gulp-uglify": "^1.5.1"
},
"devDependencies": {
"gulp-minify-html": "^1.0.4"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down

0 comments on commit a3b3650

Please sign in to comment.