-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
74 lines (64 loc) · 1.67 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
'use strict';
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const babelify = require('babelify');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const replace = require('gulp-replace-task');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const plumber = require('gulp-plumber');
const filter = require('gulp-filter');
const gulpif = require('gulp-if');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const replacements = [
{
match: /https:\/\/api.zotero.org/g,
replacement: 'https://apidev.zotero.org'
},
{
match: /http(s?):\/\/(www\.)?zotero.org/g,
replacement: 'http$1://test.zotero.net'
}
];
function onError(err) {
console.warn(err);
}
function getBuild(dev) {
var b = browserify({
debug: true,
entries: './src/libzotero.js',
standalone: 'Zotero',
}).transform(babelify).ignore('w3c-xmlhttprequest');
return b.bundle()
.pipe(source('libzotero.js'))
.pipe(buffer())
.pipe(plumber({errorHandler: onError}))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(gulpif(dev, replace({
patterns: replacements
})))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build/'))
.pipe(filter('*.js'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('build'));
}
gulp.task('default', function() {
return getBuild(false);
});
gulp.task('dev', function() {
return getBuild(true);
});
gulp.task('prepublish', function() {
return gulp.src('./src/**/*.js')
.pipe(babel())
.pipe(gulp.dest('./lib/'));
});
module.exports = {
replacements: replacements,
gulp: gulp
};