-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
101 lines (95 loc) · 2.78 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
94
95
96
97
98
99
100
101
'use strict';
const gulp = require('gulp');
const fs = require('fs');
const gulpLoadPlugins = require('gulp-load-plugins');
const del = require('del');
const path = require('path');
const runSequence = require('run-sequence');
const babelify = require('babelify');
const connect = require('gulp-connect');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const $ = gulpLoadPlugins();
const clientDistFolder = 'dist/';
gulp.task('clean', del.bind(null, ['dist/*']));
gulp.task('scss', [], () => {
return gulp.src(['./src/scss/vplyr.scss'])
.pipe($.changed('dist/', {
extension: '.css'
}))
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.sass().on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']
}))
.pipe($.sourcemaps.write())
.pipe(gulp.dest(clientDistFolder))
.pipe($.connect.reload());
})
function doBundle(b) {
return b.bundle()
.on('error', console.error.bind(console))
.pipe(source('vplyr.js')) //将常规流转换为包含Stream的vinyl对象,并且重命名
.pipe(buffer())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest(clientDistFolder))
.pipe($.connect.reload())
}
gulp.task('scripts', [], function () {
let b = browserify({
entries: './src/js/index.js',
standalone: 'vPlayer',
debug: true,
transform: ['babelify', 'browserify-versionify'],
plugin: ['browserify-derequire']
});
return doBundle(b);
});
gulp.task('watch', [], () => {
connect.server({
livereload: true,
port: 8088
});
gulp.watch(['src/js/**/*.js'], ['scripts'])
gulp.watch(['src/scss/**/*.scss'], ['scss'])
})
gulp.task('default', ['clean', 'scss', 'scripts', 'watch']);
gulp.task('build:minify:js', () => {
let options = {
sourceMap: true,
sourceMapIncludeSources: true,
sourceMapRoot: './src/',
mangle: true,
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true
}
};
return gulp.src('dist/vplyr.js')
.pipe($.rename({ extname: '.min.js' }))
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.uglify(options))
.on('error', console.error.bind(console))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('./dist/'));
})
gulp.task('build:minify:css', () => {
return gulp.src(['dist/vplyr.css'])
.pipe($.rename({ extname: '.min.css' }))
.pipe($.cleanCss({
advanced: false,
compatibility: 'ie7',
}))
.pipe(gulp.dest('./dist/'));
})
gulp.task('build', ['clean', 'scss', 'scripts'], function () {
runSequence('build:minify:js', 'build:minify:css');
});