正确的方式来定制Bower安装的组件 [英] Proper way to customize Bower-installed components
问题描述
当我使用Bower安装 bootstrap-sass-official
之类的东西时,它会将它安装在 bower_components
目录中。像Bootstrap这样的组件允许通过编辑文件 bower_components / assets / stylesheets / _bootstrap.scss
来进行自定义。在这种情况下,您可以简单地选择您要用于项目的Bootstrap的哪些部分。
众所周知,离开是最有效和最好的做法包和组件,如 ./ bower_components
, ./ vendor ,
./ node_modules
等出于源代码管理。但问题在于,当其他人下载源代码并安装bower依赖项时,您的自定义设置将永远不会安装。因此,假设您遵循最佳实践并保留 bower_components
超出源码控制,哪里是自定义组件的最佳位置,如Bootstrap?只需将 _bootstrap.scss
复制到源代码管理的目录并在其中进行自定义?或者有没有更优雅的方法?
我相信你说的最正确的解决方案是复制 _bootstrap.scss
文件添加到您的项目结构中。然后,您可以删除希望排除的引导组件,并修改剩余组件的路径以指向您的 bower_components
目录。通过这种方式,您可以在保留一个文件的情况下完全自定义库。
When I use Bower to install something like bootstrap-sass-official
, it installs it in the bower_components
directory. A component like Bootstrap allows for customization by editing the file bower_components/assets/stylesheets/_bootstrap.scss
. In this case, you simple pick and choose which parts of Bootstrap you want to use for your project.
It is well known that it is most efficient and best practice to leave packages and components like ./bower_components
, ./vendor
, ./node_modules
etc out of source control. But the problem with this is that when others download your source and install the bower dependencies, your customizations are never installed.
So, assuming that you are following best practices and keeping bower_components
out of source control, where is the best place to customize a component like Bootstrap? Simply copy _bootstrap.scss
to a source-controlled directory and customize it there? Or is there a more elegant approach?
I believe you are correct in saying that the most elegant solution is to copy the _bootstrap.scss
file to your project structure. You could then remove the bootstrap components that you wish to exclude, and modify the paths of the remaining components to point to your bower_components
directory. In this way you get full customization over the library while only maintaining a single file.
This answer might also be helpful to those looking into this issue.
这篇关于正确的方式来定制Bower安装的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!