WebStorm:我如何将HTML链接到已安装的JS库? [英] WebStorm: How can I link the HTML to an installed JS library?

查看:283
本文介绍了WebStorm:我如何将HTML链接到已安装的JS库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与WebStorm合作。我使用它的内置功能来安装jQuery。它现在出现在项目的外部库部分。



但我无法将我的Html文件链接到它(< script src =???>< / script> )。如何做到这一点?

解决方案

你不能。在设置/语言和框架/ JavaScript /库(并在项目窗口中显示为外部库)中配置的JavaScript库完全与< script> 标记中的引用无关。 IDE用于代码完成/导航/错误突出显示,后者在运行时由浏览器使用。浏览器对IDE中配置的JavaScript库一无所知,IDE不会在HTML文件中使用< script> 引用。
您需要将CDN链接指定为URL(例如 http: //code.jquery.com/jquery-2.0.0.min.js )或将WebStorm从〜/ .WebStorm9 / system / extLibs下载的文件复制到您的项目目录并指定相对于您的路径.html文件。



让我试着清理一下。应该使用哪些库:默认情况下,完成适用于项目根目录下的所有JavaScript文件。所以,如果你的项目结构中已经有了库.js文件,那就足够了。如果他们错过了,并且不想用所有这些文件敲打项目,则可以将它们存储在外部(在项目之外),并将它们配置为库以使它们可供WebStorm使用。还要注意,与项目中的.js文件相比,库是轻量级的 - 它们被视为只读,并且检查关闭。另外,您可以为它们分配文档URL,为库代码启用外部文档。因此,即使你的项目中有你的库文件,将它们作为库添加也是有意义的。因此,总结一下:



•项目结构中放置在源文件旁边的库文件可供WebStorm和浏览器使用,无论它们是否添加到设置中的JavaScript库中。

•通过HTML中的CDN链接引用的联机库在运行时可供浏览器使用,但不能用于在
IDE中完成



•放置在项目外部并配置为JavaScript库的库文件将可用于WebStorm完成,
但不会被浏览器加载


I'm working with WebStorm. I used it's built-in feature to install jQuery. It now appears in the External Libraries section of the project.

But I can't link my Html files to it (<script src="???"></script>). How can this be done?

解决方案

You can't. Javascript libraries configured in Settings/Languages&Frameworks/JavaScript/Libraries (and shown as external libraries in the Project window) have absolutely nothing to do with references in <script> tag. The former are used by IDE for code completion/navigation/error highlighting, the latter are used by browser in runtime. Browser knows nothing about javascript libraries configured in IDE, IDE doesn't use <script> references in your HTML files. You need to either specify a CDN link as URL (like "http://code.jquery.com/jquery-2.0.0.min.js") or copy the file downloaded by WebStorm from ~/.WebStorm9/system/extLibs to your project directory and specify a path relative to your .html file.

Let me try to clear the things up. What libraries are supposed to be used for: by default, completion works for all JavaScript files located under your project root. So, if you do already have the library .js files in your project structure, it's enough to get the completion. If they are missing, and you don't like to clatter your project with all these files, you can store them externally (outside of your project) and configure them as libraries to make them available to WebStorm. Note also that libraries are 'light-weight' as compared to .js files in your project - they are treated read-only, have the inspections turned off. Plus, you can assign documentation URLs to them, enabling external documentation for library code. So, even if you have your library files in your project, it might make sense to add them as libraries

So, to summarize:

•library files placed next to your sources files in the project structure are available to both WebStorm and browser, whether or not they are added to javascript libraries in Settings

•online library referenced via CDN link in your HTML is available to the browser at runtime, but can't be used for completion in the IDE

•a library files placed outside of the project and configured as javascript libraries will be available to WebStorm for completion, but won't be loaded by a browser

这篇关于WebStorm:我如何将HTML链接到已安装的JS库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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