forked from storybook-eol/react-treebeard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
70 lines (59 loc) · 1.74 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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var babel = require('gulp-babel');
var eslint= require('gulp-eslint');
var open = require('gulp-open');
var del = require('del');
var url = require('url');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var webpackConfig = {
example: require('./example/webpack.config.js')
};
var WPACK_DEV_HOST = 'localhost';
var WPACK_DEV_PORT = 8080;
var urlBuilder = function(host, port, path){
return url.format({
protocol: 'http',
hostname: host,
port: port,
pathname: path
});
};
gulp.task('open', function(){
var path = 'webpack-dev-server/index.html';
var uri = urlBuilder(WPACK_DEV_HOST, WPACK_DEV_PORT, path);
gulp.src('').pipe(open({ uri: uri }));
});
gulp.task('clean', function(cb){
del(['lib']).then(function(){
cb();
});
});
gulp.task('babel', ['clean'], function(){
return gulp.src('src/*.js')
.pipe(babel())
.pipe(gulp.dest('lib'));
});
gulp.task('webpack-dev-server', function(){
new WebpackDevServer(webpack(webpackConfig.example), {
publicPath: '/assets/',
contentBase: 'example',
hot: true,
stats: { colors: true }
}).listen(WPACK_DEV_PORT, WPACK_DEV_HOST, function(err){
if(err){ throw new gutil.PluginError('webpack-dev-server', err); }
});
});
gulp.task('lint', function(){
return gulp.src(['src/**/*.js', 'test/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
});
gulp.task('watch', function() {
gulp.watch('src/**/*.js', ['lint']);
gulp.watch('test/**/*.js', ['lint']);
});
gulp.task('build', ['clean', 'babel']);
gulp.task('default', ['webpack-dev-server', 'open']);