-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.babel.js
82 lines (77 loc) · 2.75 KB
/
gulpfile.babel.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
// Load plugins
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload'),
del = require('del');
// output path
var distpath = 'dist/assets/';
// css
gulp.task('css', function() {
return sass('src/css/screen.scss',{ style: 'expanded' })
.on('error',notify.onError(function (error) {return 'Sass error!'}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.on('error',notify.onError(function (error) {return 'Sass error!'}))
.pipe(gulp.dest(distpath + 'css'))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.on('error',notify.onError(function (error) {return 'Sass error on min!'}))
.pipe(gulp.dest(distpath + 'css'));
});
// js
gulp.task('js', function() {
return gulp.src('src/js/**/*.js')
//.pipe(concat('main.js'))
.pipe(gulp.dest(distpath + 'js'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.on('error',notify.onError(function (error) {return 'Js error!'}))
.pipe(gulp.dest(distpath + 'js'));
});
// font
gulp.task('font', function(){
return gulp.src('src/font/**/*')
.on('error',notify.onError(function (error) {return 'Font error!'}))
.pipe(gulp.dest(distpath + 'font'));
});
// img
gulp.task('img', function() {
return gulp.src('src/img/**/*')
//.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.on('error',notify.onError(function (error) {return 'Img error!'}))
.pipe(gulp.dest(distpath + 'img'));
});
// Watch
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('src/css/**/*.scss', ['css']);
// Watch .js files
gulp.watch('src/js/**/*.js', ['js']);
// Watch image files
gulp.watch('src/img/*', ['img']);
// Watch font files
gulp.watch('src/font/*', ['font']);
// Create LiveReload server
livereload.listen();
// Watch any files in assets/, reload on change
gulp.watch([distpath + '**']).on('change', livereload.changed);
});
//develop
gulp.task('develop', ['font', 'css', 'js', 'img', 'watch']);
//clean
// 清空图片、样式、js
gulp.task('clean', function(cb) {
return del([distpath + 'css', distpath + 'js',distpath + 'img',distpath + 'font'],cb);
});
// gulp命令默认启动的就是default认为,这里将clean任务作为依赖,也就是先执行一次clean任务,流程再继续.
gulp.task('default', ['clean'], function() {
gulp.start('develop');
});