简体   繁体   English

gulp构建任务-合并并缩小模块

[英]gulp build task - concat and minify modules

What is a good strategy for concatenating and minifying modules? 连接和缩小模块的好策略是什么?

I want to take this: 我要这样:

<script type="text/javascript" src="bower_components/angular-route/angular-route.js"></script>
<script type="text/javascript" src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script type="text/javascript" src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
<script type="text/javascript" src="bower_components/satellizer/satellizer.min.js"></script>
etc...

And make it this: 并使其成为:

<script src="js/all_bower_components.js"></script>

I am running this build process for my other js files, which are concatenated and minified into main.js , but that's easy because my folder structure for my own JS files is relatively predictable. 我正在为其他js文件运行此构建过程,这些文件已串联并缩小为main.js ,但这很容易,因为我自己的JS文件的文件夹结构相对可预测。 But my bower components is not: 但是我的凉亭组件不是:

bower_components/
   angular/
       angular.js
       index.js
       other random js files which aren't the ones I need
   jquery/
       dist/
           jquery.js
       src/
           bunch of other crap

I am attempting it as such: Loop through all components and sub folders and simply search for .js files... but again, this could be including things I do not need like index.js in Angular: 我正在这样尝试:遍历所有组件和子文件夹并仅搜索.js文件...但是,再次,这可能包括我不需要的东西,例如Angular中的index.js

gulp.task('modules', function() {
    return gulp.src(['bower_components/**/*.js'])
        .pipe(concat('modules.js'))
        .pipe(uglify())
        .pipe(gulp.dest('public/js'));
});

Any thoughts? 有什么想法吗?

have you tried main-bower-files ? 您是否尝试过main-bower-files this gulp plugin will capture all your base bower .js and .css by looking in your components' bower.json file for which files to grab (those listed as main ). 这个gulp插件将通过在组件的bower.json文件中查找要抓取的文件(列出为main )来捕获您的所有基本bower .js和.css。 you can override the defaults within your call to the plugin for any requirements that don't match their bower.json config. 您可以在调用插件时覆盖默认设置,以解决与bower.json配置不匹配的任何要求。 i've found this very useful for bundling a vendor.js and vendor.css for a dependency-heavy app. 我发现这对于将依赖严重的应用程序绑定vendor.js和vendor.css非常有用。

good luck! 祝好运!

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

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