使用 grunt 连接所有供应商 javascript 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16377674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using grunt to concatenate all vendor javascript files?
提问by Zando
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:
我正在使用 Yeoman (v1.x) 和 grunt (v0.4.2) 来构建一个 Angular 项目。该build
任务连接了我所有的app/script
JS 文件,但它使我所有的依赖文件都未连接,因此我构建的 index.html 进行了这些调用:
<script src="components/angular-unstable/angular.js"></script>
<script src="components/jquery/jquery.js"></script>
<script src="components/angular-resource/angular-resource.js"></script>
<script src="components/bootstrap/js/bootstrap-dropdown.js"></script>
<script src="components/moment/moment.js"></script>
<script src="components/underscore/underscore.js"></script>
<!-- xxxxxbuild:js scripts/scripts.js -->
<script src="scripts/274baf7d.scripts.js"></script>
I would like all of the components 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?
我希望我的项目使用的所有组件,即angular.js
,,jquery.js
等等,都在scripts.js
. 重新配置 GruntFile 这样做容易吗?或者这不是出于实际原因默认执行的吗?
回答by Simon Boudrias
Yes, this is easy to configure. Just add the vendors scripts in the sources you pass the grunt concat
task.
是的,这很容易配置。只需在传递 gruntconcat
任务的源中添加供应商脚本。
// Project configuration.
grunt.initConfig({
concat: {
dist: {
src: ['vendors/**/*.js', 'scripts/**/*.js'],
dest: 'built.js'
}
}
});