forked from JoseCDB/instascan
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
executable file
·57 lines (49 loc) · 1.47 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
var gulp = require('gulp');
var rename = require('gulp-rename');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var babelify = require('babelify');
var babel = require('gulp-babel');
var transform = require('gulp-transform');
var babelOptions = {
ignore: /zxing\.js$/i,
presets: ['env'],
plugins: ['transform-runtime']
};
var build = function (file) {
return browserify(file, { noParse: [ require.resolve('./src/vendor/zxing') ] })
.transform(babelify, babelOptions)
.bundle()
.pipe(source('instascan.js'));
}
var mockImportsInZXing = function (content, file) {
if (/zxing\.js$/i.test(file.relative)) {
return content.replace(/require\([^)]+\)/g, '{}');
} else {
return content;
}
};
gulp.task('default', ['build', 'watch']);
gulp.task('watch', function () {
gulp.watch('./src/*.js', ['build']);
gulp.watch('./*.js', ['build']);
});
gulp.task('build-package', function () {
return gulp.src('./src/**/*.js')
.pipe(transform('utf-8', mockImportsInZXing))
.pipe(babel(babelOptions))
.pipe(gulp.dest('./lib/'));
});
gulp.task('build', ['build-package'], function () {
return build('./export.js')
.pipe(gulp.dest('./dist/'));
});
gulp.task('release', ['build-package'], function () {
return build('./export.js')
.pipe(buffer())
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./dist/'));
});