awesome-cordova-plugins/gulpfile.js

59 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-11-25 04:04:16 +08:00
var gulp = require("gulp"),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
sourcemaps = require("gulp-sourcemaps"),
2015-11-25 01:07:41 +08:00
concat = require("gulp-concat"),
2015-11-25 04:04:16 +08:00
connect = require('gulp-connect'),
browserify = require('browserify'),
watchify = require('watchify'),
babel = require('babelify');
2015-11-25 01:07:41 +08:00
2015-11-25 04:04:16 +08:00
function compile(watch) {
var bundler = watchify(browserify()
.require('./src/index.js', {
entry: true,
2015-11-25 06:55:09 +08:00
expose: 'cordova-wrap'
2015-11-25 04:04:16 +08:00
})
.transform(babel, {presets: ['es2015']}));
function rebundle() {
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
2015-11-25 06:55:09 +08:00
.pipe(source('cordova-wrap.js'))
2015-11-25 04:04:16 +08:00
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
}
if (watch) {
bundler.on('update', function() {
console.log('-> bundling...');
rebundle();
});
}
rebundle();
}
function watch() {
return compile(true);
}
gulp.task("default", ['build'], function () { });
2015-11-25 01:07:41 +08:00
gulp.task('build', function() {
2015-11-25 04:04:16 +08:00
return compile();
2015-11-25 01:07:41 +08:00
});
2015-11-25 04:04:16 +08:00
gulp.task('watch', function() {
return watch();
});
2015-11-25 01:07:41 +08:00
gulp.task('serve', function() {
connect.server({
root: '.'
});
});