我已经用自耕农生成了一个AngularJS项目,并且有标准的'Allo',Allo!页面工作。
然后我决定在项目中添加restangular,执行“bower install restangular”,正确安装了包(bower list显示了restangular引用)。
但是,我希望index.html文件能够使用对restangular及其依赖项的正确脚本引用自动更新。
我是否使用错误的yeoman约定来安装其他依赖项?
答案 0 :(得分:5)
亚当是对的。处理此问题的最可靠方法是通过bower_components/your-installed-package/
捕获要包含的文件。目前,包装作者并未始终使用Bower。更具体地说,一些作者指定了bower.json
并定义了"main": "path/to/file.js"
。但是,有些/大多数没有。如果没有定义,那么魔法可以发生多少就会受到限制,因为这取决于脚本最好的猜测应该包含的主文件是什么。
我写了一个咕噜咕噜的任务来试图帮助解决这个问题,但是当一个包定义了main
属性时会注入一个脚本:https://github.com/stephenplusplus/grunt-bower-install
您可以说:bower install jquery --save
grunt bower-install:jquery
如果你试一试,请告诉我它是怎么回事!
答案 1 :(得分:1)
您可以使用grunt-bower-install https://github.com/stephenplusplus/grunt-bower-install来完成此操作。按照他的指示,例如将配置添加到Gruntfile,并将注释块添加到index.html。
使用bower install yourpackage -S
安装所需的软件包。你需要-S才能将它添加到bower.json
如果bower-install告诉您无法自动获取,请转到app / bower_components / yourpackage / bower.json并添加"main": "path/to/file.js"
您可以使用数组执行多个文件,例如:
"main": ["lib/persistence.js", "lib/persistence.store.mysql.js", "lib/persistence.sync.js"]
我还发现将bower-install添加到常见的grunt任务非常有用,这样您就不需要调用grunt bower-install
。这是将其添加到grunt serve
任务:
grunt.registerTask('serve', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'bower-install',
'clean:server',
'concurrent:server',
'autoprefixer',
'connect:livereload',
'watch'
]);
});
答案 2 :(得分:0)
静态使用Bower软件包的最简单方法是从脚本标记手动引用软件包:
<script src="bower_components/modernizr/modernizr.js"></script>
听起来你走在正确的轨道上。只需将脚本标记添加到HTML中即可。