generated from g3w-suite/g3w-client-plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
82 lines (72 loc) · 1.89 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
//Gulp
const gulp = require('gulp');
const rename = require('gulp-rename');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gulpif = require('gulp-if');
const uglify = require('gulp-uglify');
const gutil = require("gulp-util");
const browserify = require('browserify');
const babelify = require('babelify');
const watchify = require('watchify');
const vueify = require('vueify');
const stringify = require('stringify');
const sourcemaps = require('gulp-sourcemaps');
let production = false;
let sourcemap = false;
gulp.task('browserify', [], function() {
var bundler = browserify('./index.js', {
basedir: "./",
paths: ["./", '../'],
debug: !production,
cache: {},
packageCache: {}
});
if (!production) bundler = watchify(bundler);
bundler.transform(vueify)
.transform(babelify, {
babelrc: true
});
bundler.transform(stringify, {
appliesTo: { includeExtensions: ['.html'] }
});
var bundle = function(){
return bundler.bundle()
.on('error', function(err){
console.log(err);
process.exit();
})
.pipe(source('build.js'))
.pipe(buffer())
.pipe(gulpif(sourcemap, sourcemaps.init()))
.pipe(gulpif(production, uglify({
compress: {
drop_console: true
}
}).on('error', gutil.log))
)
.pipe(rename('plugin.js'))
.pipe(gulpif(sourcemap, sourcemaps.write('.')))
.pipe(gulp.dest('.'));
};
var rebundle;
const del = require('del');
del(['./plugin.js.map']);
if (!production) {
rebundle = function(){
return bundle();
};
bundler.on('update', rebundle);
}
else {
rebundle = function(){
return bundle();
}
}
return rebundle();
});
gulp.task('production', function(){
production = true;
});
gulp.task('watch',['browserify']);
gulp.task('build',['production','browserify']);