Skip to content

Commit ccbffb5

Browse files
committed
fix: 修复 alias 中对于 { xyz: "/some/dir" } 的适配
1 parent e39eb9a commit ccbffb5

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/models/Config.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ var Config = function () {
109109
}, {
110110
key: 'setCompiler',
111111
value: function setCompiler(compileConfig) {
112+
var _this2 = this;
113+
112114
if (compileConfig) {
113115
var nextConfig = {};
114116

115-
// 获取用户定义的compile配置
117+
// 获取用户定义的 compile 配置
116118
if ((typeof compileConfig === 'undefined' ? 'undefined' : _typeof(compileConfig)) === 'object') {
117119
nextConfig = compileConfig;
118120
} else if (typeof compileConfig === 'function') {
@@ -134,7 +136,19 @@ var Config = function () {
134136
});
135137
}
136138

137-
// 处理 resolve.root
139+
// 处理 alias 中 { xyz: "/some/dir" } 的情况
140+
if (nextConfig.resolve && nextConfig.resolve.alias) {
141+
(function () {
142+
var alias = nextConfig.resolve.alias;
143+
Object.keys(alias).map(function (key, i) {
144+
if (key.indexOf('$') === -1 && /^\/.+/.test(alias[key])) {
145+
alias[key] = sysPath.join(_this2._config.cwd, alias[key]);
146+
}
147+
});
148+
extend(true, _this2._config.resolve.alias, alias);
149+
})();
150+
}
151+
138152
var context = nextConfig.context || this._config.context;
139153
this._config.resolve.root.push(context);
140154

src/models/Config.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Config {
9797
if (compileConfig) {
9898
let nextConfig = {}
9999

100-
// 获取用户定义的compile配置
100+
// 获取用户定义的 compile 配置
101101
if (typeof compileConfig === 'object') {
102102
nextConfig = compileConfig
103103
} else if (typeof compileConfig === 'function') {
@@ -119,7 +119,17 @@ class Config {
119119
})
120120
}
121121

122-
// 处理 resolve.root
122+
// 处理 alias 中 { xyz: "/some/dir" } 的情况
123+
if (nextConfig.resolve && nextConfig.resolve.alias) {
124+
let alias = nextConfig.resolve.alias
125+
Object.keys(alias).map((key, i) => {
126+
if(key.indexOf('$') === -1 && /^\/.+/.test(alias[key])) {
127+
alias[key] = sysPath.join(this._config.cwd, alias[key])
128+
}
129+
})
130+
extend(true, this._config.resolve.alias, alias);
131+
}
132+
123133
const context = nextConfig.context || this._config.context
124134
this._config.resolve.root.push(context)
125135

0 commit comments

Comments
 (0)