-
Notifications
You must be signed in to change notification settings - Fork 13
/
require.build.js
73 lines (63 loc) · 1.86 KB
/
require.build.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
(function () {
var config = {
name: "_Meta",
out: "Bastelstu.be.Chat.js",
useStrict: true,
preserveLicenseComments: false,
optimize: 'none',
excludeShallow: [
'_Meta'
],
rawText: {
'_Meta': 'define([], function() {});'
},
paths: {
'Bastelstu.be': 'files_wcf/js/Bastelstu.be'
},
onBuildRead: function(moduleName, path, contents) {
if (!process.versions.node) {
throw new Error('You need to run node.js');
}
if (moduleName === '_Meta') {
if (global.allModules === undefined) {
var fs = module.require('fs'),
path = module.require('path');
global.allModules = [];
var queue = ['Bastelstu.be'];
var folder;
while (folder = queue.shift()) {
var files = fs.readdirSync('files_wcf/js/' + folder);
for (var i = 0; i < files.length; i++) {
var filename = path.join(folder, files[i]).replace(/\\/g, '/');
if (path.extname(filename) === '.js') {
global.allModules.push(filename);
}
else if (fs.statSync('files_wcf/js/' + filename).isDirectory()) {
queue.push(filename);
}
}
}
}
return 'define([' + global.allModules.map(function (item) { return "'" + item.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\.js$/, '') + "'"; }).join(', ') + '], function() { });';
}
return contents;
}
};
var _isSupportedBuildUrl = require._isSupportedBuildUrl;
require._isSupportedBuildUrl = function (url) {
var result = _isSupportedBuildUrl(url);
if (!result) return result;
if (Object.keys(config.rawText).some(module => url.endsWith(`${module}.js`))) return result;
var fs = module.require('fs');
try {
fs.statSync(url);
}
catch (e) {
console.log('Unable to find module:', url, 'ignoring.');
return false;
}
return true;
};
if (module) module.exports = config;
return config;
})();