VS Code js編譯支持alias

VS Code 的編譯器 其實就是使用的 typescript 編譯器,就是之前提到過的 tsserver.jshtml

相應的編譯參數能夠參考 http://www.typescriptlang.org/docs/handbook/compiler-options.htmltypescript

編譯配置的話,只須要在項目中編寫 jsconfig.json 或 tsconfig.jsonjson

 

1.增長配置屬性this

   沒仔細研究該怎麼配置,直接按照paths的進行復制spa

  

{
    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方法中增長code

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

 

相關文章
相關標籤/搜索