javascript - Gulp任务: get files with wiredep concatenate other js files and minify

标签 javascript

我正在尝试构建一个 gulp 任务,使用wiredep获取所有bower_components文件,然后将它们连接在一起。然后将我在一个特殊文件夹中的其他一些 JS 文件连接起来,最后缩小所有内容。

问题是我不知道是否可以在 Bower_components 目录之外指定wiredep另一个目录。如果这不可能,我可以使用其他解决方案吗?

我是一个使用 gulp 的初学者,因此如果您能指出我如何看待我的任务的任何其他错误,我们将不胜感激。

var wiredep = require('wiredep')(
    {
      directory: 'static/bower_components', // default: '.bowerrc'.directory || bower_components
    }).stream;
gulp.task('scripts',function(){

    return gulp
        .src('index.html') //I don´t really know what to put in the src
        .pipe(wiredep())
        .pipe($.inject(gulp.src("More  JS files if wire dep can´t handle them")))
        .pipe(minify())
        .pipe(gulp.dest('static/dist/src/app.min.js'));
});

最佳答案

我会有一个像这样的方法(可能在项目根目录的配置文件中)来获取您想要使用wiredep连接的任何内容:

getWiredepDefaultOptions: function() {
    var options = {
      directory: bower.directory,//file path to /bower_components/
    };
    return options;
},

然后在你的 gulp 任务中,有这样的内容:

gulp.task('wiredep', function() {
  log('Wiring the bower dependencies into the html');

  var wiredep = require('wiredep').stream;
  var options = config.getWiredepDefaultOptions();

  return gulp
    .src('./index.html')
    .pipe(wiredep(options))
    .pipe(gulp.dest("wherever you want your index.html"));
});

根据您想要连接的其他内容,您必须使用 index.html 中的标签添加某种排序。

关于javascript - Gulp任务: get files with wiredep concatenate other js files and minify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38724092/

相关文章:

javascript - AngularJS 指令隔离范围

javascript - 显示在另一个类中搜索的结果

javascript - react js Formik <Form/> resetForm() 不工作

用于常量字符串映射的Javascript数据结构?

c# - 有没有办法从 FCKEditor 中删除所有不必要的 MS Word 格式

javascript - 将 Javascript 变量插入到 Flask 应用程序中,然后将其插入到 Mysql 数据库中

javascript - 如何在 bxslider 控件中添加非事件类?

javascript - 二维六边形网格的透视坐标

javascript - 如何在 Jest 中模拟未安装的 npm 包?

javascript - 在 IE 中禁用 CSS 动画效果