Visibility and Scope
Each WebStorm library is characterized by its visibility status and scope. The visibility status of a library determines whether it can be used in one project (Project) or can be re-used at the IDE level (Global).
-
Once configured, a Global library can be associated with any of WebStorm projects.
The library itself can be located wherever you need, its settings are stored with other WebStorm settings in the dedicated directories
under the WebStorm home directory, depending on your operating system.
The advantage of configuring a framework as a global library is that you can store such library in one location and re-use it in unlimited number of your projects without copying the library under the project root every time.
The disadvantage of this approach is that to enable team work on the project all the team members have the library stored on their machines in the same location relative to the project root.
-
A Project library is visible only within one single project.
Therefore a project library can be associated only with this project or its part, in other words, the scope of a project library
is restricted to the current project or its part.
This means that project libraries cannot be re-used, so if you later try to use a framework configured as a project library with another project,
you will have to configure the library anew.
The advantage of configuring a JavaScript framework as a project library is that you can share the library definition among other team members through the project settings so each developer does not have to configure the library separately,
To use a self-developed JavaScript library, configure it as a WebStorm library.
-
Predefined libraries bring JavaScript definitions (also known as “stubs”) for the standard DOM, HTML5 and EcmaScript API, as well as for Node.js global objects.
These libraries make the basis for coding assistance in accordance with the API provided by the corresponding JavaScript engine. By enabling a certain predefined library
you can ensure that your code fits the target environment.
Predefined libraries are by default enabled in the scope of the entire project. A predefined library can be disabled or associated with another scope but it cannot be deleted.
The scope of a library defines the set of files and folders in which the library is considered as library, that is, it is write-protected, excluded from check for errors and refactoring, affects the completion list and highlighting.
- Open the file in the editor.
-
Click the Hector icon
on the Status bar.
The pop-up window that opens shows the list of libraries associates with the current file. To change the list, click the Libraries in scope links
and edit the scope settings in the Manage Scope dialog box that opens.
- Open the Project Settings dialog box.
- Under the JavaScript node, click JavaScript Libraries.
- In the Libraries area, click the Download button.
- The Download Library dialog box that opens, shows a list of the most popular libraries with indications of their versions and URL addresses they are available through. Select the required library and click the Download and Install button. You return to the JavaScript Libraries page where the new library is added to the list. CLick OK to save the settings.
- Open the Project Settings dialog box and click JavaScript Libraries.
- In the Libraries area, click the Add button.
- In the New Library dialog box that opens, specify the name of the library, the framework to configure the library from, and framework version to use.
-
Specify the library visibility:
- To enable associating the library with the current project only, choose Current project.
- To make the library available in any WebStorm project, choose Global.
- Create a list of files to be included in the library.
- In the New Library/Edit Library dialog box, click the Attach button and select the required file or directory in the dialog box that opens. WebStorm returns to the New Library dialog box where the Name read-only field shows the name of the selected library file or the names of relevant library files from the selected directory.
- In the Type field, specify which version of library you have downloaded and are going to add.
- Choose Debug if you are adding a library file with uncompressed code. This version is helpful in the development environment, especially for debugging.
-
Choose Release if you are adding a library file with minified
code.
This version is helpful in the production environment because the file size is significantly smaller.
It is recommended that you always have a debug version on hand along with the minified one. Minified code is hard to read and hard for WebStorm to handle. When a debug version is available, WebStorm automatically detects and ignores the minified file and retrieves definitions and documentation from the debug version.
-
Specify the URL addresses to access the documentation for library files.
- To add a link to the documentation for a library, select the corresponding library file, click the Specify button in the Documentation URLs area, and specify the documentation URL in the dialog box that opens.
- To remove a link, select it in the Documentation URLs and click the Remove button.
- In the New Library/Edit Library dialog box, select the required library file and click the Remove button.
- Open the Project Settings dialog box and click JavaScript Libraries.
- In the Libraries area, select the required library and click the Edit button.
- In the Edit Library dialog box that opens, add library files, remove library files, and change links to documentation as necessary.
- Open the Project Settings dialog box and click JavaScript Libraries.
- In the Libraries area, select the required library and click the Remove button.
The scope of a library defines the set of files and folders in which the library is considered as library, that is, it is write-protected, excluded from check for errors and refactoring, affects the completion list and highlighting.
By default, all predefined libraries and libraries downloaded from within WebStorm provide completion, resolution, highlighting and are treated as libraries in any file within the project. In other words, their usage scope is the whole project.
Libraries that you create yourself are not considered libraries in any of the files unless you specify their usage scope explicitly.
- Open the Project Settings dialog box, and click JavaScript Libraries under the JavaScriptnode.
- In the JavaScript. Libraries page that opens, click the Manage Scopes button.
- In the JavaScript Libraries. Usage Scope dialog box that opens, specify the custom JavaScript libraries to use in files and folders within your project.
To appoint a library for a file or folder, select the required item in the File/Directory field
and choose the relevant library from the Library drop-down list.
Note
The contents of the list depend on the visibility type of the configured libraries. Global libraries are on the list in all WebStorm projects. Project libraries are on the list only within the project they were originally configured in.
