-
Notifications
You must be signed in to change notification settings - Fork 53
/
gulpfile.js
85 lines (74 loc) · 2.17 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
'use strict';
var gulp = require('gulp'),
deploy = require('gulp-gh-pages'),
gutil = require('gulp-util'),
shell = require('gulp-shell'),
stylus = require('gulp-stylus'),
header = require('gulp-header'),
rename = require('gulp-rename'),
minifyCSS = require('gulp-minify-css'),
browserSync = require('browser-sync'),
argv = require('yargs').argv,
webpack = require('webpack'),
webpackConfig = require('./webpack.config.js'),
nib = require('nib');
gulp.task('webpack', function(callback) {
var jsFilename = webpackConfig.output.filename;
if (argv.production || argv.p) {
webpackConfig.output.filename = gutil.replaceExtension(jsFilename, '.min.js');
webpackConfig.plugins = webpackConfig.plugins.concat(
new webpack.DefinePlugin({
'process.env': { 'NODE_ENV': JSON.stringify('production') }
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
}
webpack(webpackConfig).run(function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString({ colors: true }));
callback();
});
});
gulp.task('css', function () {
if (argv.production || argv.p) {
return gulp.src('./dist/react-video.css')
.pipe(minifyCSS())
.pipe(rename({ suffix: '.min'}))
.pipe(header(require('./utils/banner')))
.pipe(gulp.dest('./dist'));
}
else {
return gulp.src('./lib/*.styl')
.pipe(stylus({ use: [nib()], errors: true }))
.pipe(header(require('./utils/banner')))
.pipe(gulp.dest('./dist'));
}
});
gulp.task('server', function() {
browserSync({
open: false,
notify: false,
server: {
baseDir: ['example', 'dist']
}
});
});
gulp.task('watch', function() {
gulp.watch('./lib/**/*.jsx', ['webpack', browserSync.reload]);
gulp.watch('./lib/*.styl', ['css', browserSync.reload]);
});
gulp.task('deploy', function () {
gulp.src('./docs/**/*')
.pipe(deploy());
});
gulp.task('bundle', shell.task([
'gulp webpack',
'gulp webpack -p',
'gulp css',
'gulp css -p',
'gulp deploy'
]));
gulp.task('default', ['css', 'webpack', 'server', 'watch']);