是否可以将 vs 代码配置为导入将使用绝对路径(非相对)? [英] Is it possible to configure vs code such way that import will use absolute path (not relative)?

查看:24
本文介绍了是否可以将 vs 代码配置为导入将使用绝对路径(非相对)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上次更新后的 VSCode 现在知道如何自动添加导入.但是,它使用相对路径添加了 - 知道这是否可以以某种方式配置吗?

VSCode after the last update now knows how to automatically add imports. However it adds using relative paths - any idea if that is somehow configurable?

推荐答案

如果您使用 VS Code 1.24 和 TypeScript >= 2.9,则可配置.

It is configurable if you are using VS Code 1.24 and TypeScript >= 2.9.

来自发行说明,

您现在可以明确指定 VS Code 的引用和路径样式用于自动导入和其他生成的 JavaScript 和 TypeScript代码.

Preferences for auto imports and generated code

You can now explicitly specify the quote and path styles that VS Code uses for auto imports and other generated JavaScript and TypeScript code.

[...]

javascript.preferences.importModuleSpecifiertypescript.preferences.importModuleSpecifier 设置指定类型用于导入的路径.

The javascript.preferences.importModuleSpecifier and typescript.preferences.importModuleSpecifier settings specify the type of path to use for imports.

有效值为:

  • 相对" 到文件位置.
  • "non-relative" 基于 jsconfig.json/tsconfig.json 中配置的 baseUrl.
  • "auto" 来推断最短路径类型.
  • "relative" to the file location.
  • "non-relative" based on the baseUrl configured in your jsconfig.json / tsconfig.json.
  • "auto" to infer the shortest path type.

这些新的首选项需要 TypeScript 2.9+.

These new preferences require TypeScript 2.9+.

这篇关于是否可以将 vs 代码配置为导入将使用绝对路径(非相对)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆