-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
73 lines (60 loc) · 1.94 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
// 引入 gulp
var gulp = require('gulp');
// 引入组件
var sass = require('gulp-sass'),
connect = require('gulp-connect'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
minifycss = require('gulp-minify-css'),
autoprefixer = require('gulp-autoprefixer'),
browserify = require('gulp-browserify'),
notify = require('gulp-notify'),
livereload = require('gulp-livereload'),
port = process.env.port || 8080;
// live reload
gulp.task('connect',function(){
connect.server({
// root:'./',
port: port,
livereload: true,
})
})
//scripts
gulp.task('scripts', function() {
gulp.src('./src/js/*.js')
.pipe(concat('Jsmi.js'))
.pipe(gulp.dest('build/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('build/js'))
.pipe( connect.reload() )
.pipe(notify({ message: 'Scripts common task complete' }));
});
gulp.task('html', function() {
gulp.src('./**.html')
.pipe( connect.reload() )
.pipe(notify({ message: 'html common task complete' }));
});
//编译Sass,Autoprefix及缩小化
gulp.task('style', function() {
return gulp.src('./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('./build/js/tpl'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('./build/js/tpl'))
.pipe( connect.reload() )
.pipe(notify({ message: 'Styles Common task complete' }));
});
/* 监听 */
gulp.task('watch', function() {
// 看守所有 scss
gulp.watch('src/scss/*.scss', ['scss']);
// 看守所有.js档
gulp.watch('src/js/*.js', ['scripts']);
// 看守所有.html
gulp.watch('./**.html',['html']);
});
gulp.task('serve',['connect','watch']);