1 Star 0 Fork 35

-苏若年-/bilibili-react

forked from WhiteBlue/bilibili-react 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gulpfile.babel.js 3.45 KB
一键复制 编辑 原始数据 按行查看 历史
WhiteBlue 提交于 2016-01-05 13:18 . animation add
import gulp from 'gulp';
import autoprefixer from 'autoprefixer';
import browserify from 'browserify';
import watchify from 'watchify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import eslint from 'gulp-eslint';
import babelify from 'babelify';
import uglify from 'gulp-uglify';
import rimraf from 'rimraf';
import notify from 'gulp-notify';
import browserSync, { reload } from 'browser-sync';
import sourcemaps from 'gulp-sourcemaps';
import postcss from 'gulp-postcss';
import nested from 'postcss-nested';
import vars from 'postcss-simple-vars';
import extend from 'postcss-simple-extend';
import cssnano from 'cssnano';
import htmlReplace from 'gulp-html-replace';
import imagemin from 'gulp-imagemin';
import pngquant from 'imagemin-pngquant';
import runSequence from 'run-sequence';
import ghPages from 'gulp-gh-pages';
const paths = {
bundle: 'app.js',
srcJsx: 'src/Index.js',
srcCss: 'src/**/*.css',
srcImg: 'src/images/**',
srcLint: ['src/**/*.js', 'test/**/*.js'],
dist: 'dist',
distJs: 'dist/js',
distImg: 'dist/images',
distDeploy: './dist/**/*'
};
const customOpts = {
entries: [paths.srcJsx],
debug: true
};
const opts = Object.assign({}, watchify.args, customOpts);
gulp.task('clean', cb => {
rimraf('dist', cb);
});
gulp.task('browserSync', () => {
browserSync({
server: {
baseDir: './'
}
});
});
gulp.task('watchify', () => {
let bundler = watchify(browserify(opts));
function rebundle() {
return bundler.bundle()
.on('error', notify.onError())
.pipe(source(paths.bundle))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.distJs))
.pipe(reload({stream: true}));
}
bundler.transform(babelify)
.on('update', rebundle);
return rebundle();
});
gulp.task('browserify', () => {
browserify(paths.srcJsx, {debug: true})
.transform(babelify)
.bundle()
.pipe(source(paths.bundle))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.distJs));
});
gulp.task('styles', () => {
gulp.src(paths.srcCss)
.pipe(sourcemaps.init())
.pipe(postcss([vars, extend, nested, autoprefixer, cssnano]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dist))
.pipe(reload({stream: true}));
});
gulp.task('htmlReplace', () => {
gulp.src('index.html')
.pipe(htmlReplace({css: 'styles/main.css', js: 'js/app.js'}))
.pipe(gulp.dest(paths.dist));
});
gulp.task('images', () => {
gulp.src(paths.srcImg)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(paths.distImg));
});
gulp.task('lint', () => {
gulp.src(paths.srcLint)
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('watchTask', () => {
gulp.watch(paths.srcCss, ['styles']);
gulp.watch(paths.srcJsx, ['lint']);
});
gulp.task('deploy', function () {
return gulp.src(paths.distDeploy)
.pipe(ghPages());
});
gulp.task('watch', cb => {
runSequence('clean', ['browserSync', 'watchTask', 'watchify', 'styles', 'lint', 'images'], cb);
});
gulp.task('build', cb => {
process.env.NODE_ENV = 'production';
runSequence('clean', ['browserify', 'styles', 'htmlReplace', 'images'], cb);
});
//js压缩处理
gulp.task('script', function () {
gulp.src('dist/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('minify/js'))
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/dennisit/bilibili-react.git
[email protected]:dennisit/bilibili-react.git
dennisit
bilibili-react
bilibili-react
master

搜索帮助