-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
166 lines (136 loc) · 4.26 KB
/
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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*!
* Superjoin module loader
* Copyright by Andi Heinkelein <andi.oxidant@noname-media.com>
*
* @module Superjoin
*/
(function(window) {
'use strict';
/**
* Load a module
*
* Loads a local or npm module. If the module name starts with an . a local module will be loaded.
*
* @param {string} module Loads a module
* @return {any} Returns the loaded module.
*/
var require = function(file) {
if (require.alias && require.alias[file]) {
file = require.alias[file];
}
var module = {
exports: {},
file: file
};
file = require.resolve(this && this.file ? this.file : './', file);
var requireFunc = require.bind({
file: file
});
if (window.require.cache[file]) {
if (window.require.cache[file].obj) {
return window.require.cache[file].obj;
}
window.require.cache[file].fn(module, module.exports, requireFunc);
window.require.cache[file].obj = module.exports;
return window.require.cache[file].obj;
}
if (!window.require.autoload || (window.require.autoload && file.charAt(0) !== '.')) {
throw new Error('Module ' + file + ' not found!');
}
var remoteFile = location.protocol
.concat('//', location.host)
.concat(file.substr(1));
var xhr = new XMLHttpRequest();
xhr.open('GET', remoteFile, false);
xhr.send();
if (xhr.status !== 200) {
throw new Error('Could not load module "' + file + '"! Response error: ' +
xhr.status + ' ' + xhr.statusText);
}
var source = xhr.responseText;
var fn;
try {
//jshint evil:true
fn = eval('(function(module, exports, require) {\n' +
(/\.json$/.test(file) ? 'module.exports = ' : '') +
source + '\n})\n\n//# sourceURL=' + file);
}
catch (err) {
throw new Error(err + ' in ' + file);
}
fn(module, module.exports, require.bind(requireFunc));
window.require.cache[file] = {
fn: fn,
calls: 1,
obj: module.exports,
loaded: true
};
return window.require.cache[file].obj;
};
require.resolve = function(from, to) {
var resolved = [];
if (to.indexOf('/') === -1) {
if (to.indexOf('.') === -1 || this.moduleExists(to)) {
return to;
}
}
var newPath = from.split('/');
if (newPath[0] === '.' || newPath.length > 1) {
newPath.pop();
}
var mod = to.split('/');
newPath = newPath.concat(mod);
if (this.moduleExists(mod[0])) {
newPath = mod;
}
newPath.forEach(function(p) {
if (p === '..') {
resolved.pop();
return;
}
else if (p === '.' || p === '') {
return;
}
resolved.push(p);
});
resolved = resolved.join('/');
if (!/\.js(on)?$/.test(resolved)) {
resolved += '.js';
}
if (!from || from.charAt(0) === '.') {
if (mod[0] === '.' || !this.moduleExists(mod[0])) {
resolved = './' + resolved;
}
}
return resolved;
};
require.register = function(alias, path, fn) {
if (arguments.length === 2) {
fn = path;
path = alias;
alias= null;
}
require.cache[path] = {fn: fn, calls: 0};
if (alias) {
require.alias[alias] = path;
}
};
require.moduleExists = function(mod) {
return !!require.cache[mod] || !!require.alias[mod];
};
require.cache = {};
require.alias = {};
window.require = require;
})(window);
require.register('libs/lib1.js', function(module, exports, require) {
'use strict';
var lib2 = require('./lib2');
module.exports = lib2;
});
require.register('./index.js', function(module, exports, require) {
var $ = require('jquery');
var XQCore = require('xqcore');
var mode1 = {};
module.exports = mod1;
});
require('./index.js');