-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·60 lines (56 loc) · 1.71 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify');
gulp.task('scripts', function() {
return gulp.src('assets/js/index.js')
//js代码校验
.pipe(jshint())
.pipe(jshint.reporter('default'))
//给文件添加.min后缀
.pipe(rename({
suffix: '.min'
}))
//压缩脚本文件
.pipe(uglify())
//输出压缩文件到指定目录
.pipe(gulp.dest('assets/js/'))
//提醒任务完成
.pipe(notify({
message: 'Scripts task complete'
}));
});
gulp.task('styles', function() {
//编译sass
return gulp.src('_sass/*.scss')
.pipe(sass())
//添加前缀
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
//合并为 index.css
.pipe(concat('index.css'))
//给文件添加.min后缀
.pipe(rename({
suffix: '.min'
}))
//压缩样式文件
.pipe(minifycss())
//输出压缩文件到指定目录
.pipe(gulp.dest('assets/css'))
//提醒任务完成
.pipe(notify({
message: 'Styles task complete'
}));
});
// Watch
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('_sass/*.scss', ['styles']);
// Watch .js files
gulp.watch('assets/js/index.js', ['scripts']);
});
gulp.task('default', ['watch', 'scripts', 'styles']);