可以自动将<script>标签写入index.html吗?

我使用yeoman的骨干发电机,我跑这个:

bower install backbone.localStorage -S 

我手动不得不插入到index.html中:

 <script src="bower_components/backbone.localStorage/backbone.localStorage.js"></script> 

有没有方法让鲍尔自动插入<script>标签? 我认为,鲍尔的好处的一部分是不需要找出包括你的脚本的顺序?

赶紧跑

 grunt bowerInstall 

凉亭安装后

您可以使用wiredep将依赖关系从bower推送到您的HTML代码中。 这是您运行yo angular时由generator-angular使用的方法:

 var wiredep = require('wiredep'); wiredep({ directory: 'app/bower_components', bowerJson: JSON.parse(fs.readFileSync('./bower.json')), ignorePath: 'app/', htmlFile: 'app/index.html', cssPattern: '<link rel="stylesheet" href="{{filePath}}">' }); 

Bower不会添加对这样的特定function的支持,但很快会允许您指定在“安装新软件包”之后采取的操作。 这将被称为“后安装”,类似于NPM。

同时,我创build了一个图书馆来帮助解决这个问题。 由于您使用的是yeoman,只需将“grunt-bower-install”添加为npm“devDependency”,然后按照以下说明操作: https : //github.com/stephenplusplus/grunt-bower-install 。

使用 – 保存

 bower install --save <YOUR_PACKAGE> 

–save选项使用依赖关系更新bower.json文件。 这将使您无需手动将其自动添加到bower.json中。 您将看到index.html底部的脚本部分已经自动更新。

参考:http: //yeoman.io/codelab/install-packages.html