1 Star 0 Fork 0

音视频解决方案/flv.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gulpfile.js 3.93 KB
一键复制 编辑 原始数据 按行查看 历史
xqq 提交于 2017-09-08 23:28 . auto-reload: Fix details
/*
* Copyright (C) 2016 Bilibili. All Rights Reserved.
*
* @author zheng qian <xqq@xqq.im>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const del = require('del');
const gulp = require('gulp');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const eslint = require('gulp-eslint');
const sourcemaps = require('gulp-sourcemaps');
const babelify = require('babelify');
const browserify = require('browserify');
const watchify = require('watchify');
const buffer = require('vinyl-buffer');
const source = require('vinyl-source-stream');
const browserSync = require('browser-sync').create();
function doWatchify() {
let customOpts = {
entries: 'src/index.js',
standalone: 'flvjs',
debug: true,
transform: ['babelify', 'browserify-versionify'],
plugin: ['browserify-derequire']
};
let opts = Object.assign({}, watchify.args, customOpts);
let b = watchify(browserify(opts));
b.on('update', function () {
return doBundle(b).on('end', browserSync.reload.bind(browserSync));
});
b.on('log', console.log.bind(console));
return b;
}
function doBundle(b) {
return b.bundle()
.on('error', console.error.bind(console))
.pipe(source('flv.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/'));
}
function doLint(paths, exit) {
return gulp.src(paths)
.pipe(eslint())
.pipe(eslint.format())
.pipe(exit ? eslint.failAfterError() : eslint.result(function () {}));
}
gulp.task('default', ['clean', 'lint', 'build']);
gulp.task('release', ['clean', 'lint', 'build', 'minimize']);
gulp.task('watch', ['clean'], function () {
let gulpWatcher = gulp.watch(['gulpfile.js', 'src/**/*.js']);
gulpWatcher.on('change', function (e) {
if (e.type === 'changed' || e.type === 'added') {
return doLint(e.path, false);
}
});
return doBundle(doWatchify()).on('end', function () {
browserSync.init({
server: {
baseDir: './'
},
port: 8000,
open: false
});
require('opn')('http://localhost:8000/demo/index.html');
});
});
gulp.task('clean', function () {
return del([
'dist/*'
]);
});
gulp.task('lint', function () {
return doLint(['gulpfile.js', 'src/**/*.js'], true);
});
gulp.task('build', ['clean', 'lint'], function () {
let b = browserify({
entries: 'src/index.js',
standalone: 'flvjs',
debug: true,
transform: ['babelify', 'browserify-versionify'],
plugin: ['browserify-derequire']
});
return doBundle(b);
});
gulp.task('minimize', ['lint', 'build'], function () {
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/flv.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/'));
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/media-solution/flv.js.git
git@gitee.com:media-solution/flv.js.git
media-solution
flv.js
flv.js
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385