forked from kybarg/react-qr-scanner
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
45 lines (38 loc) · 1.31 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
const gulp = require('gulp')
const fs = require('fs')
const del = require('del')
const inlineStr = require('gulp-inline-str')
const babel = require('gulp-babel')
const uglify = require('gulp-butternut')
const concat = require('gulp-concat')
const path = require('path')
const babelOptions = JSON.parse(fs.readFileSync('./.babelrc', 'utf8'))
const paths = {
scripts: [ 'src/index.js', 'src/getDeviceId.js', 'src/havePropsChanged.js', 'src/errors.js' ],
worker: 'src/worker.js',
jsQR: path.relative('./', require.resolve('jsqr')),
destination: './lib',
}
gulp.task('clean', function() {
return del([ paths.destination + '/*.js' ])
})
gulp.task('worker', gulp.series('clean', function() {
return gulp
.src([ paths.jsQR, paths.worker ])
.pipe(concat('worker.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.destination))
}))
gulp.task('build', gulp.series('worker', function() {
return gulp
.src(paths.scripts)
.pipe(inlineStr({ basePath: paths.destination }))
.pipe(babel(babelOptions))
.pipe(gulp.dest(paths.destination))
}))
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.scripts, gulp.series('build'))
})
// The default task (called when you run `gulp` from cli)
gulp.task('default', gulp.series('build'))