-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgulpfile.js
58 lines (51 loc) · 1.6 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
var babelify = require('babelify');
var browserify = require('browserify');
var uglify = require('gulp-uglify');
var watchify = require('watchify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var assign = require('lodash.assign');
var plugins = require('gulp-load-plugins')();
var options = {
debug: false,
fullPaths: false,
standalone: 'wxmlparser'
};
function createBundler(entry) {
options = plugins.util.env.production ? options :
assign(options, { debug: true, fullPaths: true, cache: {}, packageCache: {} });
options.entries = [entry];
var b = browserify(options);
b.transform('babelify', { presets: ['es2015'] });
return b;
}
function bundle(b, out) {
return b.bundle()
.on('error', plugins.util.log.bind(plugins.util, 'Browserify Error'))
.pipe(source(out))
.pipe(buffer())
.pipe(plugins.util.env.production ? uglify() : gutil.noop())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'));
}
gulp.task('build', function() {
var bundler = createBundler('index.js');
return bundle(bundler, 'wxml-parser.js')
});
gulp.task('test', function() {
var bundler = createBundler('test/test.js');
bundler.plugin(watchify);
bundler.on('update', function() {
bundle(bundler, 'test.js');
gutil.log('Rebundle...');
});
bundle(bundler, 'test.js');
});
gulp.task('default', function() {
var bundler = createBundler('test/test.js');
return bundle(bundler, 'test.js')
});