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 9512a1d commit c8af502
Show file tree
Hide file tree
Showing 23 changed files with 163 additions and 25 deletions.
Empty file added app/css/main.css
Empty file.
11 changes: 11 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/index.css">
</head>
<body>
hello world22
</body>
</html>
3 changes: 3 additions & 0 deletions app/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* Created by Administrator on 2015-12-22.
*/
3 changes: 3 additions & 0 deletions app/js/tmp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* Created by Administrator on 2015-12-22.
*/
6 changes: 6 additions & 0 deletions app/less/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
color: red;
}
h2 {
color: red;
}
8 changes: 8 additions & 0 deletions app/less/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@xxx: red;

body {
color: @xxx;
}
h2 {
color: @xxx;
}
1 change: 1 addition & 0 deletions build/jquery/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('jquery2');
1 change: 1 addition & 0 deletions build/js/src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('src3');
6 changes: 6 additions & 0 deletions dist/css/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
color: red;
}
h2 {
color: red;
}
11 changes: 11 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/index.css">
</head>
<body>
hello world22
</body>
</html>
1 change: 0 additions & 1 deletion dist/js/src.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/src.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/target.js/src.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/xx.js/yy.js/src.js

This file was deleted.

37 changes: 20 additions & 17 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
var gulp = require('gulp');
var rename = require('gulp-rename');
//定义一个任务
var a = 0;
gulp.task('a+',function(cb){
//one是一个异步执行的任务
setTimeout(function(){
a++;
console.log('a++');
cb();
},3000);
var less = require('gulp-less');
var connect = require('gulp-connect');

gulp.task('copyhtml',function(){
gulp.src('app/index.html').pipe(gulp.dest('dist')).pipe(connect.reload());
});
gulp.task('a-',function(){
//one是一个异步执行的任务
setTimeout(function(){
a--;
console.log('a--');
},3000);

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

gulp.task('default',['a+','a-']);
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']);
24 changes: 24 additions & 0 deletions history/connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var gulp = require('gulp');
var less = require('gulp-less');
var connect = require('gulp-connect');

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

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']);
4 changes: 4 additions & 0 deletions history/copymultifiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var gulp = require('gulp');
gulp.task('copy-other',function(){
return gulp.src(['app/css/*.css','app/js/*.js','!app/js/tmp.js'],{base:'app'}).pipe(gulp.dest('dist'));
});
10 changes: 10 additions & 0 deletions history/copysinglefile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var gulp = require('gulp');

/**
* 匹配多个目录 glob
* 可以填写一个数组
*
*/
gulp.task('copy-other',function(){
return gulp.src(['app/css/*.css','app/js/*.js']).pipe(gulp.dest('dist'));
});
11 changes: 11 additions & 0 deletions history/returnstream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var gulp = require('gulp');

gulp.task('one',function(cb){
var stream = gulp.src('script/**/*.js')
.pipe(gulp.dest('build'));
//return stream;
});

gulp.task('default',['one'],function(){
console.log('default is done');
});
21 changes: 21 additions & 0 deletions history/task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var gulp = require('gulp');
var rename = require('gulp-rename');
//定义一个任务
var a = 0;
gulp.task('a+',function(cb){
//one是一个异步执行的任务
setTimeout(function(){
a++;
console.log('a++');
cb();
},3000);
});
gulp.task('a-',function(){
//one是一个异步执行的任务
setTimeout(function(){
a--;
console.log('a--');
},3000);
});

gulp.task('default',['a+','a-']);
21 changes: 21 additions & 0 deletions history/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var gulp = require('gulp');
var rename = require('gulp-rename');
//压缩JS
gulp.task('uglify',function(){
//do something
console.log('uglify');
});
//重启服务
gulp.task('reload',function(){
//do something
console.log('reload');
});
gulp.task('default',function(){
//gulp.watch('script/**/*.js', ['uglify','reload']);

gulp.watch('script/**/*.js', function(event){
console.log(event.type); //变化类型 added为新增,deleted为删除,changed为改变
console.log(event.path); //变化的文件的路径
});

});
4 changes: 1 addition & 3 deletions script/jquery/jquery.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
/**
* Created by Administrator on 2015-12-22.
*/
console.log('jquery2');
2 changes: 1 addition & 1 deletion script/js/src.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log('hello');
console.log('src3');

0 comments on commit c8af502

Please sign in to comment.