Skip to content

Commit 1506eb8

Browse files
committed
fix: 修复 alias 不生效
1 parent daaf665 commit 1506eb8

File tree

2 files changed

+27
-51
lines changed

2 files changed

+27
-51
lines changed

lib/models/Config.js

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -105,51 +105,36 @@ var Config = function () {
105105
}, {
106106
key: 'setCompiler',
107107
value: function setCompiler(compileConfig) {
108-
var _this2 = this;
109-
110108
if (compileConfig) {
111-
(function () {
112-
var nextConfig = {};
113-
114-
// 获取用户定义的compile配置
115-
if ((typeof compileConfig === 'undefined' ? 'undefined' : _typeof(compileConfig)) === 'object') {
116-
nextConfig = compileConfig;
117-
} else if (typeof compileConfig === 'function') {
118-
nextConfig = compileConfig(extend({}, _this2._config)) || {};
119-
}
109+
var nextConfig = {};
120110

121-
// 处理context
122-
if (nextConfig.context && !sysPath.isAbsolute(nextConfig.context)) {
123-
nextConfig.context = sysPath.resolve(_this2._config.cwd, nextConfig.context);
124-
}
111+
// 获取用户定义的compile配置
112+
if ((typeof compileConfig === 'undefined' ? 'undefined' : _typeof(compileConfig)) === 'object') {
113+
nextConfig = compileConfig;
114+
} else if (typeof compileConfig === 'function') {
115+
nextConfig = compileConfig(extend({}, this._config)) || {};
116+
}
125117

126-
// 处理loaders => loader
127-
if (nextConfig.module && nextConfig.module.loaders) {
128-
nextConfig.module.loaders.map(function (loader, i) {
129-
if (loader.loaders && !loader.loader) {
130-
loader.loader = loader.loaders.join("!");
131-
}
132-
return loader;
133-
});
134-
}
118+
// 处理 context
119+
if (nextConfig.context && !sysPath.isAbsolute(nextConfig.context)) {
120+
nextConfig.context = sysPath.resolve(this._config.cwd, nextConfig.context);
121+
}
135122

136-
// 处理alias
137-
var context = nextConfig.context || _this2._config.context;
138-
var relativeContext = sysPath.relative(_this2._config.cwd, context);
139-
if (nextConfig.resolve && nextConfig.resolve.alias) {
140-
(function () {
141-
var alias = nextConfig.resolve.alias;
142-
Object.keys(alias).map(function (key, i) {
143-
alias[key] = sysPath.relative(relativeContext, alias[key]);
144-
});
145-
extend(true, _this2._config.resolve.alias, alias);
146-
})();
147-
}
123+
// 处理 loaders => loader
124+
if (nextConfig.module && nextConfig.module.loaders) {
125+
nextConfig.module.loaders.map(function (loader, i) {
126+
if (loader.loaders && !loader.loader) {
127+
loader.loader = loader.loaders.join("!");
128+
}
129+
return loader;
130+
});
131+
}
148132

149-
_this2._config.resolve.root.push(context);
133+
// 处理 resolve.root
134+
var context = nextConfig.context || this._config.context;
135+
this._config.resolve.root.push(context);
150136

151-
extend(true, _this2._config, nextConfig);
152-
})();
137+
extend(true, this._config, nextConfig);
153138
}
154139
}
155140
}, {

src/models/Config.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ class Config {
100100
nextConfig = compileConfig(extend({}, this._config)) || {};
101101
}
102102

103-
// 处理context
103+
// 处理 context
104104
if (nextConfig.context && !sysPath.isAbsolute(nextConfig.context)) {
105105
nextConfig.context = sysPath.resolve(this._config.cwd, nextConfig.context)
106106
}
107107

108-
// 处理loaders => loader
108+
// 处理 loaders => loader
109109
if (nextConfig.module && nextConfig.module.loaders) {
110110
nextConfig.module.loaders.map((loader, i) => {
111111
if (loader.loaders && !loader.loader) {
@@ -115,17 +115,8 @@ class Config {
115115
})
116116
}
117117

118-
// 处理alias
118+
// 处理 resolve.root
119119
const context = nextConfig.context || this._config.context
120-
const relativeContext = sysPath.relative(this._config.cwd, context)
121-
if (nextConfig.resolve && nextConfig.resolve.alias) {
122-
let alias = nextConfig.resolve.alias
123-
Object.keys(alias).map(function(key, i) {
124-
alias[key] = sysPath.relative(relativeContext, alias[key])
125-
})
126-
extend(true, this._config.resolve.alias, alias);
127-
}
128-
129120
this._config.resolve.root.push(context)
130121

131122
extend(true, this._config, nextConfig);

0 commit comments

Comments
 (0)