forked from PaulLeCam/react-leaflet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
110 lines (92 loc) · 2.59 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var gulp = require("gulp");
var $ = require("gulp-load-plugins")();
var del = require("del");
var source = require("vinyl-source-stream2");
var browserify = require("browserify");
var reactify = require("reactify");
var watchify = require("watchify");
var src = [
"./src/**/*",
"!./src/__tests__",
"!./src/__tests__/**",
"!./src/**/__tests__",
"!./src/**/__tests__/**"
];
var lib = "./lib";
var exampleSrc = "./example";
var exampleBuild = "./example/build";
var logTime = function(fileName) {
var name = $.util.colors.cyan(fileName);
return function(ms) {
var time = ms < 1000
? $.util.colors.magenta(ms + " ms")
: $.util.colors.magenta(ms / 1000 + " s");
$.util.log("Browserified '" + name + "' in " + time);
};
};
var bundleExample = function(b, fileName) {
return b.bundle()
.pipe(source(fileName))
.pipe(gulp.dest("./example/build"));
};
var watchExample = function(b, fileName) {
var w = watchify(b).on("time", logTime(fileName));
var bundle = function() {
return bundleExample(w, fileName);
};
w.on("update", bundle);
return bundle();
};
simpleBundler = browserify(exampleSrc + "/app.js", watchify.args)
.external("react")
.external("react/addons")
.external("leaflet")
.external("react-leaflet")
.transform(reactify, {es6: true});
gulp.task("clean:lib", function(cb) {
del(lib + "/**", cb);
});
gulp.task("compile", ["clean:lib"], function() {
return gulp.src(src)
.pipe($.react({harmony: true}))
.pipe(gulp.dest(lib));
});
gulp.task("watch", ["compile"], function() {
gulp.watch(src, ["compile"]);
});
gulp.task("example:deps", function() {
var bundler = browserify()
.require("react")
.require("react/addons")
.require("leaflet");
return bundleExample(bundler, "dependencies.js");
});
gulp.task("example:lib", function() {
var bundler = browserify()
.external("react")
.external("react/addons")
.external("leaflet")
.require("./", {expose: "react-leaflet"})
return bundleExample(bundler, "lib.js");
});
gulp.task("example:server", function() {
return gulp.src("./example")
.pipe($.webserver({
fallback: "index.htm"
}));
});
gulp.task("example:app", function() {
return bundleExample(simpleBundler, "app.js");
});
gulp.task("watch:example:lib", ["example:deps"], function() {
return gulp.watch("./lib/**", ["example:lib"]);
});
gulp.task("watch:example:app", ["example:deps", "example:lib"], function() {
return watchExample(simpleBundler, "app.js");
});
gulp.task("watch:example", [
"example:server",
"watch:example:lib",
"watch:example:app"
]);
gulp.task("default", ["compile"]);