-
Notifications
You must be signed in to change notification settings - Fork 29
/
build-js.js
executable file
·80 lines (64 loc) · 2.13 KB
/
build-js.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
#!/usr/bin/env node
var
path = require("path"),
fs = require("fs"),
uglify = require("uglify-js"),
VENDOR_FILENAME = path.join(__dirname,"js","load.vendor.js"),
SITE_FILENAME = path.join(__dirname,"js","load.site.js"),
vendor_files = [
// jquery scripts
path.join(__dirname,"js","vendor","jquery.parallax.js"),
path.join(__dirname,"js","vendor","jquery.animateSprite.js"),
path.join(__dirname,"js","vendor","jquery.transit.min.js"),
path.join(__dirname,"js","vendor","jquery.mousewheel.js"),
// "Three" scripts
path.join(__dirname,"js","vendor","Three.js","Three.js"),
path.join(__dirname,"js","vendor","Three.js","loaders","MTLLoader.js"),
path.join(__dirname,"js","vendor","Three.js","loaders","OBJMTLLoader.js"),
// Additional required scripts
path.join(__dirname,"js","vendor","grips.min.js"),
path.join(__dirname,"js","vendor","blockandtackle-libs.js"),
path.join(__dirname,"js","vendor","tween.min.js"),
path.join(__dirname,"js","vendor","h5ive.animationframe.js"),
path.join(__dirname,"js","vendor","sound.js","soundjs-0.5.0.min.js"),
path.join(__dirname,"js","vendor","history.js"),
path.join(__dirname,"js","vendor","stroll.js"),
],
site_files = [
path.join(__dirname,"js","plugins.js"),
path.join(__dirname,"js","tmpls.js"),
path.join(__dirname,"js","Pages.js"),
path.join(__dirname,"js","scrollpager.js"),
path.join(__dirname,"js","main.js"),
path.join(__dirname,"js","Twitter.js"),
path.join(__dirname,"js","twitter","interaction.js"),
]
;
function bundleJS(files) {
var bundle_str = "";
files.forEach(function(file){
console.log("Bundling: " + file.replace(/.*\//,""));
var st = fs.statSync(file), contents;
contents = fs.readFileSync(file,{ encoding: "utf8" });
try {
bundle_str += ";" + uglify.minify(contents,{ fromString: true }).code + ";";
}
catch (err) {
bundle_str += ";" + contents + ";";
}
});
return bundle_str;
}
console.log("*** Production JS build ***");
// load.vendor.js
fs.writeFileSync(
VENDOR_FILENAME,
bundleJS(vendor_files),
{ encoding: "utf8" }
);
// load.site.js
fs.writeFileSync(
SITE_FILENAME,
bundleJS(site_files),
{ encoding: "utf8" }
);