• VS Code js编译支持alias


    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;
                }
            }

  • 相关阅读:
    学习方法:费曼学习方法
    学习方法:天才的秘密
    学习方法:学习的大致过程
    OS:VM虚拟机连不上网络
    cpp:argc和argv的应用
    baidu:{{!!}}
    os:windows许可证书位置
    书法:练字的心得体会
    修复Python终端中敲击方向键显示 [ ^[[A, ^[[B, ^[[C, ^[[D ]
    jquery下removeClass(“oldClassName”).addClass("newClassName")的问题
  • 原文地址:https://www.cnblogs.com/legu/p/7228565.html
Copyright © 2020-2023  润新知