forked from ss1121/FKP-REST
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequirePath.js
More file actions
65 lines (55 loc) · 1.72 KB
/
requirePath.js
File metadata and controls
65 lines (55 loc) · 1.72 KB
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
//配置环境路径
var path = require('path')
var util = require('util')
// var base = path.resolve(__dirname);
function reRequire(base){
if (base && util.isString(base)){
var _path = {
apis: base,
db: base,
fkpdoc: base,
libs: base,
modules: base,
public: base,
pages: base,
react: base+'/public/react',
root: base
}
//封装require方法
//简化require的调用,别名化
global.include = function(file){
if (!file){
throw new Error('没有指定文件名');
}
if (typeof file !== 'string'){
throw new Error('file参数必须为String类型');
}
if (file.indexOf('/')>-1){
var tmp = file.split('/')
var key = tmp[0];
if (_path[key]){
var merge_path;
if (key==='react'){
file = file.replace('react/','')
merge_path = path.join(_path[key], file)
}
else {
if (file.indexOf('root')>-1){
file = tmp[1]
}
merge_path = path.join(_path[key], file)
}
return require(merge_path)
}
else {
throw new Error('没有该文件或者路径错误');
}
}
else {
return require(file)
}
}
require('app-module-path').addPath(base);
}
}
module.exports = reRequire