简体   繁体   English

如何根据bower / npm自动生成Tern项目文件?

[英]How to auto-generate Tern project files based on bower/npm?

I just integrated Tern with my editor of choice, and the experience has been pretty incredible so far. 我只是将Tern与我选择的编辑器集成在一起,到目前为止,这种体验非常令人难以置信。

One thing that would make the experience all the more intuitive, however, would be the ability to tap into my existing front- and back-end dependency management systems (ie the bower.json and package.json files) rather than having to manage the .tern-project file manually. 然而,使体验更直观的一件事是能够利用我现有的前端和后端依赖管理系统(即bower.jsonpackage.json文件),而不是必须管理.tern-project文件手动。

Is there some existing way of doing this? 有没有现成的方法呢?

Setting something like this in your .tern-project should be enough to get it aware of dependencies loaded through your package.json: .tern-project设置类似.tern-project应该足以让它知道通过package.json加载的依赖项:

{
  "plugins": {
    "node": {}
  }
}

As for bower components, you can follow these steps to get decent completion: 至于凉亭组件,您可以按照以下步骤获得良好的完成:

  • Ensure that you have a build step that copies all main js assets from your bower components into a known directory (tools like wiredep are great for this kind of thing). 确保您有一个构建步骤,将所有main js资产从您的bower组件复制到一个已知目录(像wiredep这样的工具非常适合这种事情)。
  • Set that directory into your loadEagerly property. 将该目录设置为loadEagerly属性。

That'd look something like this: 看起来像这样:

{
  "loadEagerly": [
    "path/to/Bower/dir/**/*.js"
  ]
}

If your Bower components really rely on them loading in a specific order, you could either list them in the right order in the loadEagerly list, or use the simpler approach of concatenating all these Bower components into a single file and just mentioning that in the loadEagerly list. 如果您的Bower组件确实依赖于它们按特定顺序加载,您可以在loadEagerly列表中以正确的顺序列出它们,或者使用更简单的方法将所有这些Bower组件连接到一个文件中,并在loadEagerly提及它名单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM