-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathbrowserify.js
71 lines (59 loc) · 1.56 KB
/
browserify.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
/*jslint node: true, nomen: true*/
'use strict';
var watchify = require('watchify');
var errorify = require('errorify');
var browserify = require('browserify');
var babelify = require('babelify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var path = require('path');
var paths = {
root: './',
dist: './dist/',
src: './src/'
};
var entry = 'react.js';
var options = {
cache: {},
packageCache: {},
debug: true // sourcemapping
};
function bundle(w, e) {
return w.bundle()
.pipe(source(e.replace('react', 'cleave-react')))
//.pipe(source(e))
.pipe(gulp.dest(paths.dist));
}
gulp.task('js:react:watch', function () {
options.entries = [path.join(paths.root, entry)];
options.transform = [babelify];
options.plugin = [watchify, errorify];
var w = browserify(options);
w.on('update', function () {
bundle(w, entry);
});
w.on('log', function (msg) {
console.log(msg);
});
bundle(w, entry);
return w;
});
/**
* This task is replaced by webpack
*
* I like browserify but sadly webpack doesn't
* support loading the bundled file
* generated by browserify in bundling :(
*
* https://github.com/webpack/webpack/issues/1617
*
* The other way around, browserify supports webpack bundled file,
* hence we will use the webpack bundled script
*
*/
//gulp.task('js:react', function () {
// options.entries = [path.join(paths.root, entry)];
// options.plugin = [errorify];
//
// return bundle(browserify(options), entry);
//});