WebStorm 2021.2 Help

Path variables路径变量

Path variables are placeholders that stand for absolute paths to resources that are linked to your project but are stored outside it. 路径变量是占位符,表示链接到项目但存储在项目外部的资源的绝对路径。If you are working in a team, these absolute paths on the computers of your teammates may differ. 如果您在一个团队中工作,那么您的队友的计算机上的这些绝对路径可能会有所不同。With path variables, you can flexibly share your code so all the references to the linked resources are resolved properly as the path variables accept the values according to the configuration on each specific computer.通过使用路径变量,您可以灵活地共享代码,以便在路径变量根据每个特定计算机上的配置接受值时,正确解析对链接资源的所有引用。

In WebStorm, there are some pre-defined variables:在WebStorm中,有一些预定义变量:

  • $USER_HOME$: stands for your home directory.代表您的主目录。

  • $PROJECT_DIR$: stands for the directory where your project is stored.表示存储项目的目录。

Create a new path variable创建一个新的路径变量

For example, you have a third-party library that is not stored in your project directory. If you want to make sure that the path is correct on your teammates' computers after they update the project from VCS, you can create a new variable.

  1. Press Ctrl+Alt+S to open IDE settings and select Appearance & Behavior | Path Variables.
  2. Click the Add button and enter the name of the new variable (for example, PATH_TO_LIB) and its value that points to the library location on your disk.

  3. Share the IML file through your version control system.

  4. After your teammates update their projects from VCS, they will change the PATH_TO_LIB variable value so that it points to the library location on their computers.

Ignored path variables

When you open a project, WebStorm checks if there are any unresolved path variables. If the IDE detects any, it will ask you to define values for them. If for some reason you don’t want to do that (for example, if you are not going to use files or directories with the unresolved path variables), you can add them to the list of ignored variables.

You can also use the list of ignored variables if, for example, a program argument passed to the JVM in a run/debug configuration has the same format as an internal ($SOME_STRING$) path variable. In this case, you can add this parameter to the list of ignored variables in order to avoid confusion. Enter SOME_STRING to the Ignored Variables field in the Path Variables dialog.

Last modified: 17 May 2021