forked from ronik-design/react-drive-in
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
89 lines (78 loc) · 2.44 KB
/
gulpfile.js
File metadata and controls
89 lines (78 loc) · 2.44 KB
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
var Gulp = require('gulp'),
Deploy = require('gulp-gh-pages'),
Gutil = require('gulp-util'),
Shell = require('gulp-shell'),
Less = require('gulp-less'),
Header = require('gulp-header'),
Rename = require('gulp-rename'),
MinifyCSS = require('gulp-minify-css'),
Autoprefix = require('less-plugin-autoprefix'),
BrowserSync = require('browser-sync'),
Webpack = require('webpack'),
webpackConfig = require('./webpack.config.js'),
argv = require('yargs').argv;
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-drive-in.css')
.pipe(MinifyCSS())
.pipe(Rename({
suffix: '.min'
}))
.pipe(Gulp.dest('./dist'));
} else {
return Gulp.src('./lib/*.less')
.pipe(Less({
plugins: [ new Autoprefix({ browsers: ['last 5 version'] }) ]
}))
.pipe(Header(require('./utils/banner')))
.pipe(Gulp.dest('./dist'));
}
});
Gulp.task('server', function() {
BrowserSync({
browser: 'google chrome',
server: {
baseDir: ['example', 'dist']
}
});
});
Gulp.task('watch', function() {
Gulp.watch('./lib/**/*.js?(x)', ['webpack', BrowserSync.reload]);
Gulp.watch('./lib/*.less', ['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']);