-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
146 lines (112 loc) · 4.13 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var gulp = require('gulp');
var day = '20151111h5';
// 引入组件
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;
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
// 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 +'/build/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('./'+ day +'/build/css/'))
.pipe(reload({stream: true}))
.pipe(notify({ message: 'Styles task complete' }));
});
gulp.task('onescss', function() {
return gulp.src('./'+ day +'/images/edm/emd.scss')
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(rename('emd.css'))
.pipe(minifycss())
.pipe(gulp.dest('./'+ day +'/images/edm/'))
.pipe(reload({stream: true}))
.pipe(notify({ message: 'onescss task complete' }));
});
gulp.task('home', function() {
return gulp.src('./home/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('./home/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('./home/css/'))
.pipe(reload({stream: true}))
.pipe(notify({ message: 'home style task complete' }));
});
gulp.task('html',function(){
gulp.src('./'+ day +'/*.html')
.pipe(reload({stream: true}))
});
gulp.task('homeHtml',function(){
gulp.src('./*.html')
.pipe(reload({stream: true}))
});
gulp.task('scripts',function(){
return gulp.src('./'+ day +'/src/js/*.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('./'+ day +'/build/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('./'+ day +'/build/js/'))
.pipe(reload({stream: true}))
.pipe(notify({ message: 'Scripts task complete' }));
});
//zip
gulp.task('zip', function () {
return gulp.src(['./'+ day +'/main.min.css','./'+ day +'/host.html'])
.pipe(zip('special'+ day +'.zip'))
.pipe(gulp.dest(''+ day +''))
.pipe(notify({ message: 'zip task complete' }));
});
// 静态服务器 + 监听 scss/html 文件
gulp.task('dev', ['sass'], function() {
browserSync.init({
server: './'+day+'/'
});
// 看守.scss 档
gulp.watch('./'+ day +'/src/scss/*.scss', ['sass']);
gulp.watch('./home/scss/*.scss', ['home']);
// 看守所有.js档
gulp.watch('./'+ day +'/*.js', ['scripts']);
gulp.watch('./'+ day +'/src/js/*.js', ['html','scripts']);
// 看守所有.html
gulp.watch('./'+ day +'/*.html').on('change', reload);;
gulp.watch('./*.html').on('change', reload);;
});
/* 监听 文件变化 */
gulp.task('watch', function() {
// 看守.scss 档
gulp.watch('./'+ day +'/src/scss/*.scss', ['sass']);
gulp.watch('./home/scss/*.scss', ['home']);
// 看守所有.js档
gulp.watch('./'+ day +'/*.js', ['scripts']);
gulp.watch('./'+ day +'/src/js/*.js', ['html','scripts']);
// 看守所有.html
gulp.watch('./'+ day +'/*.html',['html','zip']);
gulp.watch('./*.html',['homeHtml']);
});
gulp.task('serve',['connect','watch']);
gulp.task('default', ['dev']);