本文介绍了VS Code 能否在文件重命名/移动时自动更新 JavaScript 和 TypeScript 导入路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有用于更新文件路径的 vscode 模块?例如如果我有:

import './someDir/somelib'

并且我重命名或移动 somelib,它会自动更新上面引用的所有文件中的文件路径吗?

解决方案

此功能是在 VS Code 1.24 中为 JavaScript 和 TypeScript 添加的 (

这由 javascript.updateImportsOnFileMove.enabledtypescript.updateImportsOnFileMove.enabled 设置控制.有效值为:

  • "prompt" — 默认值.提示每个文件重命名/移动
  • "always" — 始终尝试在没有提示的情况下自动更新导入
  • "never" — 不更新导入且不提示

Is there a module for vscode that would update paths towards files? e.g. if I have:

import './someDir/somelib'

and I rename or move somelib, would it automatically update the file path in all the files where it is being referred as above?

解决方案

This feature was added for JavaScript and TypeScript in VS Code 1.24 (tracking issue)

When you move or rename a file, you will now be prompted to see if you want to update imports:

This is controlled by the javascript.updateImportsOnFileMove.enabled and typescript.updateImportsOnFileMove.enabled settings. Valid values are:

  • "prompt" — The default. Prompt for each file rename/move
  • "always" — Always try to update imports automatically without prompting
  • "never" — Do not update imports and do not prompt

这篇关于VS Code 能否在文件重命名/移动时自动更新 JavaScript 和 TypeScript 导入路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 15:56