简体   繁体   English

我应该从bower_components复制文件吗?

[英]Should I copy files from bower_components of reference them there?

After installing BackboneJS , jQuery etc I have a very large bower_components directory. 在安装BackboneJSjQuery等之后,我有一个非常大的bower_components目录。

├───.idea
│   ├───runConfigurations
│   └───scopes
└───app
    ├───bower_components
    │   ├───backbone
    │   ├───jquery
    │   │   ├───dist
    │   │   └───src
    │   │       ├───ajax
    │   │       │   └───var
    │   │       ├───attributes
    │   │       ├───core
    │   │       │   └───var
    │   │       ├───css
    │   │       │   └───var
    │   │       ├───data
    │   │       │   └───var
    │   │       ├───effects
    │   │       ├───event
    │   │       ├───exports
    │   │       ├───manipulation
    │   │       │   └───var
    │   │       ├───queue
    │   │       ├───sizzle
    │   │       │   ├───dist
    │   │       │   └───test
    │   │       │       ├───data
    │   │       │       └───unit
    │   │       ├───traversing
    │   │       │   └───var
    │   │       └───var
    │   └───underscore
    ├───css
    └───js

What is best practice to reference these? 参考这些是什么最佳做法? eg directly, Grunt task to copy bits to the main app, or put the bower_componects inside the ~/app directory? 例如,直接,Grunt任务将位复制到主应用程序,或将bower_componects放在~/app目录中?

Don't copy them over to your app - that completely defies the intent of a package manager like Bower! 不要将它们复制到您的应用程序 - 这完全违背了像Bower这样的包管理器的意图! By doing so, you'd take control over these files away from your package manager - and then you're left in the same state as before, manually having to copy over files every time with an update of these dependencies. 通过这样做,您可以控制远离包管理器的这些文件 - 然后您将保持与以前相同的状态,每次手动重置文件并更新这些依赖项。

Just reference the files inside the bower_components/ directory directly (in your HTML, most likely). 只需直接引用bower_components/目录中的文件(在HTML中,最有可能)。 If you don't like that location or name, you can have bower put your components some place else, see .bowerrc doc: http://bower.io/docs/config/ 如果您不喜欢该位置或名称,您可以让bower将您的组件放在其他位置,请参阅.bowerrc doc: http.bowerrc


I can think of a use for only using specific files from your bower_components directory - but only at build time : 我可以想到只使用bower_components目录中的特定文件 - 但仅限于构建时

If you write a grunt task that runs only at deploy time and strips away all unused files from the bower_components directory, that of course makes sense and does not go against the idea of a package manager, because it only happens on each deploy, a point when the package manager has no responsibilities. 如果你编写一个仅在部署时运行的grunt任务并从bower_components目录中bower_components所有未使用的文件,那当然是有道理的,并且不违背包管理器的想法,因为它只发生在每个部署,一个点上当包管理员没有责任时。

The only problem you might get with this approach is if you have it end up copying files over to a different directory - because then you'd have to change the references to all files from bower_components before deploying, too. 使用这种方法可能遇到的唯一问题是,如果你最终将文件复制到另一个目录 - 因为那时你必须在部署之前更改对bower_components所有文件的引用。 The easy solution is to not duplicate files, but instead, only delete the ones you don't need . 简单的解决方案是不重复文件,而只删除不需要的文件

Just leave them in bower_components and refer proper files inside your index.html file. 只需将它们保存在bower_components并在index.html文件中引用正确的文件即可。 You can do this manually, or use tools like grunt wiredep to do this for you automatically. 您可以手动执行此操作,或使用grunt wiredep等工具自动执行此操作。

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

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