VS Code js编译支持alias
2024-09-30 09:06:47
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;
}
}
最新文章
- Github的命令清除
- BZOJ4537 : [Hnoi2016]最小公倍数
- Web安全学习笔记之一
- iOS之UI--关于modal
- Java内存分配全面浅析
- iOS各种动画效果
- 30 分钟 Java Lambda 入门教程
- JS拖动div的原理
- iOS 下的相册与图片处理
- 福建省队集训被虐记——DAY3
- Https 客户端与服务器交互过程梳理(转)
- OpenCv error :unresolved external symbol(链接库没有加上)
- javascript小记四则:用JS写一个滚动横条文字,可以根据需要进行修改;
- React文档(八)条件渲染
- pandas简短介绍
- angularjs drag and drop
- RTMP HLS HTTP 直播协议一次看个够
- struct在C和C++中的使用总结
- UVA1378 A funny stone game
- mybatis的<;choose>;和<;when>;、<;otherwise>;标签