VS Code 的编译器 其实就是使用的 typescript 编译器,就是以前提到过的 tsserver.js
相应的编译参数可以参考 http://www.typescriptlang.org/docs/handbook/compiler-options.html
编译配置的话,只需要在项目中编写 jsconfig.json 或 tsconfig.json
1.增加配置属性
没仔细研究该怎么配置,直接按照paths的进行复制
{ name: "alias", type: "object", isTSConfigOnly: true, category: ts.Diagnostics.Module_Resolution_Options, description: ts.Diagnostics.A_series_of_entries_which_re_map_imports_to_lookup_locations_relative_to_the_baseUrl },
2.在LoadModule方法中增加
function _getModuleUsingBaseUrlAliasPath(alias, moduleName) { var flag = false; var path = moduleName; do { flag = false; for (var key in alias) { if (path == key || path.indexOf(key + '/') === 0) { path = alias[key] + path.substr(key.length) flag = true; } } } while(flag); return path; } function tryLoadModuleUsingBaseUrlAlias(extensions, moduleName, loader, failedLookupLocations, state) { var baseUrl = state.compilerOptions.baseUrl; var path = ''; var flag = false; var path = _getModuleUsingBaseUrlAliasPath(state.compilerOptions.alias, moduleName); if (path == moduleName) return false; var candidate = ts.normalizePath(ts.combinePaths(baseUrl, path)); var res = loader(extensions, candidate, failedLookupLocations, !directoryProbablyExists(ts.getDirectoryPath(candidate), state.host), state); return res; } function tryLoadModuleUsingBaseUrl(extensions, moduleName, loader, failedLookupLocations, state) { if (!state.compilerOptions.baseUrl) { return undefined; } if (state.traceEnabled) { trace(state.host, ts.Diagnostics.baseUrl_option_is_set_to_0_using_this_value_to_resolve_non_relative_module_name_1, state.compilerOptions.baseUrl, moduleName); } if (state.compilerOptions.alias) { var res = tryLoadModuleUsingBaseUrlAlias(extensions, moduleName, loader, failedLookupLocations, state); if (res) { return res; } }