This repository has been archived by the owner on Sep 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
76 lines (69 loc) · 1.9 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
/* eslint no-console: "off" */
'use strict';
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var browserify = require('browserify');
var plumber = require('gulp-plumber');
var babel = require('gulp-babel');
var del = require('del');
var eslint = require('gulp-eslint');
gulp.task('lint', () => {
return gulp.src([
'**/*.js',
'!node_modules/{,/**}',
'!lib/{,/**}',
'!browser/{,/**}'
]).pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lib', function() {
del(['./lib/**/*']);
gulp.src(['./src/scripts/**/*.js'])
.pipe(plumber())
.pipe(babel({
presets: ['react', 'env']
}))
.pipe(gulp.dest('lib'));
});
gulp.task('browser', function() {
var browserifyBundle = function() {
return browserify({
entries: ['./src/scripts/index.js'],
transform: [
[
'babelify', {
'presets': [ 'react', 'env' ],
'sourceMaps': true
}
]
],
standalone: 'WVC',
debug: true
})
.transform('browserify-shim', {global: true})
.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); });
};
browserifyBundle() // Unminified
.pipe(source('wvc.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('browser'));
browserifyBundle() // Minified
.pipe(source('wvc.min.js'))
.pipe(buffer())
.pipe(uglify().on('error', function(e) { console.log(e); }))
.pipe(gulp.dest('browser'));
});
gulp.task('clean-browser', function(cb) {
del(['./browser/*'], cb);
});
gulp.task('watch', function() {
gulp.watch('src/scripts/**/**/*.js', ['browser']);
});
gulp.task('default', ['clean-browser', 'browser', 'lib']);