zoukankan      html  css  js  c++  java
  • 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;
                }
            }

  • 相关阅读:
    javascript 基本数据类型
    数据库管理小工具帮助
    CSS3实现32种基本图形
    面试题2:替换空格
    面试题1:二维数组中查找
    图的深度优先和广度优先搜索算法
    Spring+Maven+Dubbo+MyBatis+Linner+Handlebars—Web开发环境搭建
    Spring学习笔记—最小化Spring XML配置
    Spring学习笔记—装配Bean
    Spring学习笔记—Spring之旅
  • 原文地址:https://www.cnblogs.com/legu/p/7228565.html
Copyright © 2011-2022 走看看