-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
128 lines (112 loc) · 3.18 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var gulp = require('gulp');
var htmlmin = require('gulp-htmlmin');
var sass = require('gulp-sass');
var less = require('gulp-less');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var livereload = require('gulp-livereload');
var webserver = require('gulp-webserver');
var clean = require('gulp-clean');
var ftp = require('gulp-ftp');
var autoprefixer = require('gulp-autoprefixer');
gulp.task('sass', function(){
return gulp.src('./sass/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(
autoprefixer({
browsers:['Android >= 4.2', 'ios>=8'],
cascade: false
})
)
.pipe(gulp.dest('./dist/css'));
})
gulp.task('sass:watch', function(){
//当scss文件变动,重新编译
gulp.watch('./sass/*.scss', ['sass'])
});
gulp.task('less', function(){
return gulp.src('./less/*.less')
.pipe(less())
.pipe(
autoprefixer({
browsers:['Android >= 4.2', 'ios>=8'],
cascade: false
})
)
.pipe(gulp.dest('./dist/css'));
})
gulp.task('less:watch', function(){
//当scss文件变动,重新编译
gulp.watch('./less/*.less', ['less'])
});
gulp.task('imagemin', function(){
gulp.src('./images/*')
.pipe(imagemin())
.pipe(gulp.dest('./dist/images'))
});
// gulp.task('compress', function(cb){
// pump([
// gulp.src('./js/*.js'),
// uglify(),
// rename('v.min.js'),
// gulp.dest('./dist/js')
// .pipe(connect.reload())
// ],
// cb
// );
// })
gulp.task('compress', ['clean-scripts'], function(cb){
return gulp.src('./js/*.js')
.pipe(uglify())
.pipe(rename('v.min.js'))
.pipe(gulp.dest('./dist/js'));
// .pipe(webserver.reload())
})
gulp.task('compress:watch', function(){
gulp.watch('./js/*.js', ['compress'])
})
gulp.task('clean-scripts', function(){
return gulp.src('./dist/js/*.js')
.pipe(clean())
})
// gulp.task('watch', function(){
//
// var server = livereload();
// gulp.watch('./dist/**', function(file){
// server.changed(file.path);
// });
//
// // livereload.listen();
// // gulp.watch(['dist/**']).on('change', function(file){
// // server.changed(file.path);
// // })
// })
gulp.task('minifyhtml', function() {
return gulp.src('./*.html')
// .pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./dist/html'))
})
gulp.task('default', function(){
gulp.start('minifyhtml', 'sass','less', 'sass:watch','less:watch', 'webserver', 'compress', 'compress:watch');
})
gulp.task('scp', ['compress'], function () {
return gulp.src('./dist/**/*')
.pipe(ftp({
host: '192.168.0.55',
user: 'ftp',
port: 21,
pass: 'Wym137138702'
}))
.on('error', function (err) {
console.log(err);
});
})
gulp.task('webserver', function() {
gulp.src('./')
.pipe(webserver({
livereload: true,
directoryListing: false,
open: 'text.html'
}));
})