简体   繁体   English

如何在网页中包含bower组件

[英]How to include bower component in a web page

I'm starting with bower and followed this tutorial at first. 我开始使用bower并首先遵循本教程 I have no problems with installing a package, but with how to use it in a static web page. 我没有安装软件包的问题,​​但是如何在静态网页中使用它。

I could obviously do something like: 我显然可以这样做:

<script src="bower_components/module_name/module.js"></script>

for each the components I need, but it seems to me not the good way to do. 对于我需要的每个组件,但在我看来,这不是一个好方法。 So I think I am missing something which could link the page generation to my bower components. 所以我想我错过了一些可以将页面生成链接到我的凉亭组件的东西。

May be there a bower component which could help me to include all packages in a bower_components directory. 可能有一个bower组件可以帮助我将所有包包含在bower_components目录中。

That is one way to do it but I usually use bower in conjunction with other build tools, like grunt or gulp . 这是一种方法,但我通常将bower与其他构建工具结合使用,例如gruntgulp Then you can use a task, like grunt-bower-task , to copy only the necessary files to a directory of your choosing. 然后,您可以使用grunt-bower-task等任务将必要的文件复制到您选择的目录中。

If you are feeling really ambitious, you could leverage the bower api to roll your own build solution that extracts the "main" files into your project. 如果您感觉非常雄心勃勃,可以利用bower api推出自己的构建解决方案,将“主要”文件提取到项目中。

Another thing to be aware of, is that not every dependency you will want to include will implement bower's configuration properly (example: missing main attribute or bower.json file). 另一件需要注意的事情是,并非您想要包含的每个依赖项都能正确实现bower的配置(例如:缺少main属性或bower.json文件)。 There will also be those projects that require you to include assets (fonts, images, etc.), which bower doesn't currently solve for. 还有一些项目要求你包括资产(字体,图像等),这是当前没有解决的凉亭。 In these cases, you will need to come up with a way to move the files around. 在这些情况下,您需要提出一种移动文件的方法。 I always end up having to use something like grunt-contrib-copy to get everything in it's place. 我总是不得不使用像grunt-contrib-copy这样的东西来获取它的所有内容。

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

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