代码拉取完成,页面将自动刷新
var gulp = require('gulp')
var babelify = require('babelify')
var browserify = require('browserify')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var uglify = require('gulp-uglify')
var rename = require('gulp-rename')
var es = require('event-stream')
var runSequence = require('run-sequence')
var cleanCSS = require('gulp-clean-css')
var cached = require('gulp-cached')
var babel = require('gulp-babel')
var del = require('del')
var browserSync = require('browser-sync')
var gzip = require('gulp-gzip')
/** ******************* serve task *********************/
// serve sharedpen source files and compile them
gulp.task('serve', ['clean:build'], () => {
runSequence(['build:scripts', 'build:css'])
browserSync({
port: 5000,
logPrefix: 'together',
server: {
baseDir: './build'
},
notify: false,
open: false
})
gulp.watch(['lib/*.js'], ['build:scripts'])
gulp.watch(['lib/*.css'], ['build:css'])
})
// compile js/css
gulp.task('build:scripts', () => {
return gulp.src('lib/*.js')
.pipe(cached('jsing'))
.pipe(babel({
presets: ['es2015'],
plugins: ['transform-es2015-modules-umd']
}))
.pipe(gulp.dest('build'))
})
gulp.task('build:css', () => {
return gulp.src('lib/*.css')
.pipe(gulp.dest('build/'))
})
// clean build dir
gulp.task('clean:build', () => {
del.sync('build')
})
/** ******************* build task *********************/
gulp.task('build', (cb) => {
runSequence('clean:build', ['build:scripts', 'build:css'], cb)
})
// bundle js/css
gulp.task('bundle:scripts', () => {
var bundles = [
{ standalone: 'togetherClient', entry: 'lib/togetherClient.js' },
{ standalone: 'togetherServer', entry: 'lib/togetherServer.js' }
]
var tasks = bundles.map((bundle) => {
return browserify(bundle.entry, { standalone: bundle.standalone })
.transform(babelify, {
presets: ['es2015']
})
.bundle()
.pipe(source(bundle.entry.slice(bundle.entry.indexOf('/') + 1).toLowerCase()))
.pipe(gulp.dest('dist/'))
// You need this if you want to continue using the stream with other plugins
.pipe(buffer())
.pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest('dist/'))
})
return es.merge.apply(null, tasks)
})
gulp.task('bundle:css', () => {
return gulp.src('lib/main.css')
.pipe(cleanCSS())
.pipe(rename({
basename: 'together'
}))
.pipe(gulp.dest('dist/'))
})
// clean dist dir
gulp.task('clean:dist', () => {
del.sync('dist')
})
gulp.task('gzip', () => {
return gulp.src('dist/**/*.min.js')
.pipe(gzip({append: true}))
.pipe(gulp.dest('dist/'))
})
/** ******************* bundle task *********************/
gulp.task('bundle', ['clean:dist'], (cb) => {
runSequence(['bundle:scripts', 'bundle:css'], 'gzip', cb)
})
gulp.task('default', ['bundle'])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。