最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angularjs - Using grunt to concatenate all vendor javascript files? - Stack Overflow

programmeradmin8浏览0评论

I'm using Yeoman (v1.x) with grunt (v0.4.2) to build an Angular project. The build task concatenates all my app/script JS files, but it leaves all of my dependency files unconcatenated, so that my built index.html makes these calls:

<script src="ponents/angular-unstable/angular.js"></script>
<script src="ponents/jquery/jquery.js"></script>
<script src="ponents/angular-resource/angular-resource.js"></script>
<script src="ponents/bootstrap/js/bootstrap-dropdown.js"></script>
<script src="ponents/moment/moment.js"></script>
<script src="ponents/underscore/underscore.js"></script>

<!-- xxxxxbuild:js scripts/scripts.js -->
<script src="scripts/274baf7d.scripts.js"></script>

I would like all of the ponents my project uses, i.e. angular.js, jquery.js, and so forth, to be in scripts.js. Is it easy to reconfigure the GruntFile to do so? Or is this not done by default for a practical reason?

I'm using Yeoman (v1.x) with grunt (v0.4.2) to build an Angular project. The build task concatenates all my app/script JS files, but it leaves all of my dependency files unconcatenated, so that my built index.html makes these calls:

<script src="ponents/angular-unstable/angular.js"></script>
<script src="ponents/jquery/jquery.js"></script>
<script src="ponents/angular-resource/angular-resource.js"></script>
<script src="ponents/bootstrap/js/bootstrap-dropdown.js"></script>
<script src="ponents/moment/moment.js"></script>
<script src="ponents/underscore/underscore.js"></script>

<!-- xxxxxbuild:js scripts/scripts.js -->
<script src="scripts/274baf7d.scripts.js"></script>

I would like all of the ponents my project uses, i.e. angular.js, jquery.js, and so forth, to be in scripts.js. Is it easy to reconfigure the GruntFile to do so? Or is this not done by default for a practical reason?

Share Improve this question asked May 4, 2013 at 18:38 ZandoZando 5,5458 gold badges34 silver badges38 bronze badges 1
  • Yes I have the same question, why is this left as a default? What happens if you use mon CDNs, does that mean they shouldn't be concatenated? Also what about things like modernizr? They cannot be concatenated either because it needs to be at the top of the page. – CMCDragonkai Commented Jul 22, 2013 at 8:37
Add a ment  | 

1 Answer 1

Reset to default 13

Yes, this is easy to configure. Just add the vendors scripts in the sources you pass the grunt concat task.

// Project configuration.
grunt.initConfig({
  concat: {
    dist: {
      src: ['vendors/**/*.js', 'scripts/**/*.js'],
      dest: 'built.js'
    }
  }
});
发布评论

评论列表(0)

  1. 暂无评论