forked from xiangst0816/AppDownloadPage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
93 lines (81 loc) · 2.08 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
var gulp = require('gulp')
var gulpLoadPlugins = require('gulp-load-plugins')
var $ = gulpLoadPlugins()
var bs = require('browser-sync')
var browserSync = bs.create()
var reload = browserSync.reload
var del = require('del')
var runSequence = require('run-sequence')
// css前缀处理配置
var AutoRreFixerParams = {
browsers: [
'last 2 versions',
'iOS >= 7',
'Android >= 4'],
cascade: false
}
gulp.task('clean', del.bind(null, ['.tmp', 'dist']))
gulp.task('style', function () {
return gulp.src('src/scss/*.scss')
.pipe($.plumber())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.sass.logError))
.pipe($.autoprefixer(AutoRreFixerParams))
.pipe(gulp.dest('.tmp/css'))
})
gulp.task('script', function () {
return gulp.src('src/js/**/*.js')
.pipe($.plumber())
.pipe(gulp.dest('.tmp/js'))
})
gulp.task('other', function () {
gulp.src('src/asset/**.*')
.pipe($.plumber())
.pipe(gulp.dest('.tmp/asset'))
gulp.src('src/index.html')
.pipe($.plumber())
.pipe(gulp.dest('.tmp'))
})
gulp.task('default', function () {
return new Promise(function (resolve) {
runSequence(['clean'], 'build', resolve)
})
})
gulp.task('build', function () {
runSequence(['style', 'script', 'other'], function () {
gulp.src('.tmp/index.html')
.pipe($.inlineSource())
.pipe($.htmlmin({collapseWhitespace: true}))
.pipe($.size({title: 'dist/index.html', gzip: true}))
.pipe(gulp.dest('dist'))
})
})
gulp.task('serve', function () {
runSequence(['clean'], ['style', 'script', 'other'], function () {
browserSync.init({
notify: false,
port: 9000,
server: {
baseDir: ['.tmp']
}
})
gulp.watch('src/scss/**/*.*', function () {
runSequence('style', function () {
reload()
})
})
gulp.watch('src/js/**/*.*', function () {
runSequence('script', function () {
reload()
})
})
gulp.watch(['src/asset/**/*.*', 'src/index.html'], function () {
runSequence('other', function () {
reload()
})
})
})
})