-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
125 lines (109 loc) · 3.42 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"use strict";
var argv = require("yargs")
.usage("Usage: $0 -o [file] -g [globals] task")
.demand(["o"])
.describe("o", "Output file").argv;
var gulp = require("gulp");
var del = require("del");
var util = require("gulp-util");
var rollup = require("rollup-stream");
var uglify = require("gulp-uglify");
var browserSync = require("browser-sync").create();
var buble = require("rollup-plugin-buble");
var nodeResolve = require("rollup-plugin-node-resolve");
var sourcemaps = require("gulp-sourcemaps");
var source = require("vinyl-source-stream");
var buffer = require("vinyl-buffer");
var rename = require("gulp-rename");
var commonjs = require("rollup-plugin-commonjs");
var json = require("rollup-plugin-json");
var outputFilename = argv.o;
var globals = [];
if (argv.g) {
globals = Array.isArray(argv.g) ? argv.g : [argv.g];
}
var skips = [];
var globalMap = {};
globals.forEach((d) => {
var target = null;
if (d.indexOf("@redsift/d3-rs") !== -1) {
var trim = d;
var paths = trim.split("/");
if (paths.length > 1) {
trim = paths.slice(1, paths.length).join("/");
}
target = trim.replace(/-/g, "_");
} else if (d.indexOf("d3-") === 0) {
target = "d3";
skips.push(d);
} else {
throw new Error("Unknown global type: " + d);
}
globalMap[d] = target;
});
var task = {};
gulp.task("clean", () => del(["distribution/**"]));
gulp.task(
"umd",
(task.umd = async () => {
return rollup({
name: outputFilename.replace(/-/g, "_"),
globals: globalMap,
input: "src/index.js",
format: "umd",
sourcemap: true,
plugins: [
json({
include: ["**/package.json", "node_modules/**/*.json"],
exclude: [],
}),
nodeResolve({
skip: skips,
// use "jsnext:main" if possible
// – see https://github.com/rollup/rollup/wiki/jsnext:main
jsnext: true, // Default: false
// use "main" field or index.js, even if it's not an ES6 module
// (needs to be converted from CommonJS to ES6
// – see https://github.com/rollup/rollup-plugin-commonjs
main: true, // Default: true
// not all files you want to resolve are .js files
extensions: [".js"], // Default: ['.js']
// whether to prefer built-in modules (e.g. `fs`, `path`) or
// local ones with the same names
preferBuiltins: false, // Default: true
}),
commonjs(),
buble(),
],
})
.pipe(source("main.js", "./src"))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(rename({ basename: outputFilename }))
.pipe(rename({ suffix: ".umd-es2015" }))
.pipe(gulp.dest("distribution/"))
.pipe(uglify())
.pipe(rename({ suffix: ".min" }))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("distribution/"));
})
);
gulp.task("browser-sync", function () {
browserSync.init({
server: {
baseDir: ["./examples", "./distribution"],
directory: true,
},
});
});
gulp.task("build", gulp.series(["clean"]), task.umd);
gulp.task("default", gulp.series(["umd"]));
gulp.task("serve", gulp.series(["default", "browser-sync"]), async function () {
gulp.watch(["./*.js", "./src/*.js"], ["umd"]);
gulp
.watch("./distribution/*.js")
.on("change", () => browserSync.reload("*.js"));
gulp
.watch("./examples/**/*.html")
.on("change", () => browserSync.reload("*.html"));
});