forked from AirtestProject/PocoHierarchyViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
85 lines (70 loc) · 2.23 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
var gulp = require('gulp');
var babel = require('gulp-babel');
var watch = require('gulp-watch');
var watchify = require('gulp-watchify');
var sourcemap = require('gulp-sourcemaps')
var jsxpath = 'lib/modules/**/*.js*';
var jsxoutput = 'lib/babel-build/';
var bundleoutput = 'lib/js-build/';
var entries = [
['viewer'],
];
gulp.task('babel-build', function () {
process.env.NODE_ENV = 'production'
return gulp.src(jsxpath)
.pipe(babel({
presets: ['es2015', 'react']
}))
.pipe(gulp.dest(jsxoutput));
});
gulp.task('babel-debug-build', function () {
return gulp.src(jsxpath)
.pipe(sourcemap.init())
.pipe(watch(jsxpath))
.pipe(babel({
presets: ['es2015', 'react'],
}))
.on('error', function (err) {
console.log(err);
return true;
})
.pipe(sourcemap.write())
.pipe(gulp.dest(jsxoutput));
});
var source = require('vinyl-source-stream')
var streamify = require('gulp-streamify')
var browserify = require('browserify')
var uglify = require('gulp-uglify')
var minify = require('gulp-minify')
var rename = require('gulp-rename')
gulp.task('bundle', ['babel-build'], function () {
process.env.NODE_ENV = 'production'
for (var i in entries) {
var dir = entries[i][0];
var shouldUglify = entries[i][1] !== 'no-uglify';
var filename = 'index.js';
var stub = browserify('./' + jsxoutput + dir + '/' + filename)
.bundle()
.pipe(source(filename));
var minified = uglify()
if (shouldUglify) {
stub = stub.pipe(streamify(minified));
}
stub.pipe(gulp.dest(bundleoutput + dir));
}
});
gulp.task('debug-bundle', watchify(function (watchify) {
return gulp.src(jsxoutput + '**/index.js')
.pipe(watchify({watch: true}))
.on('error', function () {
return true;
})
.on('finish', function () {
console.log('building finished');
})
.pipe(gulp.dest(bundleoutput));
}));
gulp.task('build', ['babel-build', 'bundle'], function () {
console.log('构建完成,正在努力打包脚本');
});
gulp.task('debug-build', ['babel-debug-build', 'debug-bundle']);