-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
54 lines (46 loc) · 1.32 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
// 引入 gulp
var gulp = require('gulp');
// 引入组件
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var rev = require('gulp-rev-hash');
var browserSync = require('browser-sync').create();
//时间戳
gulp.task('rev', function () {
gulp.src('index.html')
.pipe(rev())
.pipe(gulp.dest('.'));
});
// 编译Sass
gulp.task('sass', function () {
// gulp.src('style/*.scss')
// .pipe(sass().on('error', sass.logError))
// .pipe(gulp.dest('dist'));
});
// 检查脚本
gulp.task('lint', function () {
gulp.src('js/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// 合并,压缩文件
gulp.task('scripts', function () {
gulp.src('js/**/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('dist'));
});
// 默认任务
gulp.task('default', ['sass', 'lint', 'scripts', 'rev'], function () {
browserSync.init({
server: {
baseDir: "./"
}
});
gulp.watch(["dist/*.*"]).on("change", browserSync.reload);
// 监听文件变化
gulp.watch('js/**/*.js', ['lint', 'scripts', 'rev']);
// gulp.watch('style/*.scss', ['sass', 'rev']);
});