-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
90 lines (67 loc) · 2.31 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
var gulp = require('gulp');
var day = '20151008';
// 引入组件
var sass = require('gulp-sass'),
connect = require('gulp-connect'),
minifycss = require('gulp-minify-css'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
browserify = require('gulp-browserify'),
notify = require('gulp-notify'),
autoprefixer = require('gulp-autoprefixer'),
livereload = require('gulp-livereload'),
zip = require('gulp-zip');
port = process.env.port || 5000;
// live reload
gulp.task('connect',function(){
connect.server({
// root:'./',
port: port,
livereload: true,
})
});
//编译Sass,Autoprefix及缩小化
gulp.task('sass', function() {
return gulp.src('./'+ day +'/src/scss/main.scss')
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('./'+ day +'/dist/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('./'+ day +'/'))
.pipe( connect.reload() )
.pipe(notify({ message: 'Styles task complete' }));
});
gulp.task('html',function(){
gulp.src('./'+ day +'/*.html')
.pipe( connect.reload() )
});
gulp.task('scripts',function(){
return gulp.src('./'+ day +'/src/js/pan.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('./'+ day +'/images/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('./'+ day +'/images/js/'))
.pipe( connect.reload() )
.pipe(notify({ message: 'Scripts task complete' }));
});
//zip
gulp.task('zip', function () {
return gulp.src(['./'+ day +'/main.min.css','./'+ day +'/index.html'])
.pipe(zip('special'+ day +'.zip'))
.pipe(gulp.dest(''+ day +''))
.pipe(notify({ message: 'zip task complete' }));
});
/* 监听 文件变化 */
gulp.task('watch', function() {
// 看守.scss 档
gulp.watch('./'+ day +'/src/scss/*.scss', ['sass']);
// 看守所有.js档
gulp.watch('./'+ day +'/*.js', ['scripts']);
gulp.watch('./'+ day +'/src/js/*.js', ['html']);
// 看守所有.html
gulp.watch('./'+ day +'/*.html',['html','zip']);
});
gulp.task('serve',['connect','watch']);