-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
116 lines (104 loc) · 2.44 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
let gulp = require("gulp");
let PluginError = require("plugin-error");
let log = require("fancy-log");
let webpack = require("webpack");
const { spawn } = require("child_process");
const path = require("path");
let setProduction = (done) => {
process.env.NODE_ENV = "production";
done();
};
let setDev = (done) => {
process.env.NODE_ENV = "development";
done();
};
/** For inclusion in web pages */
function webpackOnBuild(done) {
let start = Date.now();
return function (err, stats) {
if (err) {
throw new PluginError("webpack", err);
}
log(
"[webpack]",
stats.toString({
colors: true,
})
);
let end = Date.now();
log("Build Completed, running for " + (end - start) / 1000) + "s";
if (done) {
done(err);
}
};
}
/** For external/built projects to import via NPM */
function doBuildESModules(done) {
var isWin = process.platform === "win32";
//Dirty fix for the moment to avoid commenting out the ES processes
if (isWin) {
console.log(
"doBuildESModules skipping because it doesnt seem to work under Windows:"
);
done();
return;
}
const subP = spawn(
"npx",
[
"babel",
path.join(__dirname, "src"),
"--out-dir",
path.join(__dirname, "es"),
"--env-name",
"esm",
"--verbose",
],
{ stdio: "inherit", windowsVerbatimArguments: true }
);
subP.on("close", (code) => {
done();
});
}
function doWatchESModules(done) {
var isWin = process.platform === "win32";
//Dirty fix for the moment to avoid commenting out the ES processes
if (isWin) {
console.log(
"doWatchESModules skipping because it doesnt seem to work under Windows:"
);
done();
return;
}
const subP = spawn(
"npx",
[
"babel",
path.join(__dirname, "src"),
"--out-dir",
path.join(__dirname, "es"),
"--env-name",
"esm",
"--watch",
"--skip-initial-build",
],
{ stdio: "inherit", windowsVerbatimArguments: true }
);
subP.on("close", (code) => {
done();
});
}
let buildWebpack = (cb) => {
let webpackConfig = require("./webpack.config.js");
webpack(webpackConfig).run(webpackOnBuild(cb));
};
let watchWebpack = () => {
let webpackConfig = require("./webpack.config.js");
webpack(webpackConfig).watch(300, webpackOnBuild());
};
const dev = gulp.series(setDev, buildWebpack, watchWebpack);
const buildProd = gulp.series(setProduction, buildWebpack);
const buildDev = gulp.series(setDev, buildWebpack);
gulp.task("dev", dev);
gulp.task("build-prod", buildProd);
gulp.task("build-dev", buildDev);