1

I have all of my paths defined at the top of the project,

var paths = {
  scripts: ['./js/main.js', './js/datetimepicker.js'],
  styles: ['./stylesheets/style.scss', './stylesheets/datetimepicker/datetimepicker.css', './stylesheets/vis/vis.css'],
  images: ['img/**/*'],
  libs: ['./js/*.min.js', './img/*', './fonts/FontAwesome/*'],
  compress: ['./css/**', './fonts/FontAwesome/**', './img/**', './js/main.min.js', './js/bootstrap.min.js'],
  concat: [{
    'src': './web-src/js/services*.js',
    'name': 'services.js'
  }]
};

My issue is that when I call paths.concat[0].src I am forced to specify what index in the array I want. So when I call my concat task,

gulp.task('concat', function () {
  return gulp.src(paths.concat[0].src)
    .pipe(concat(paths.concat[0].src))
    .pipe(gulp.dest('./dist/'));
});

Having the paths defined is not helpful. What is the 'best practice' way of looping over a task?

Thanks

2
  • What is a "JSON variable"? Commented Dec 31, 2015 at 3:30
  • Probably not the correct name but I'm assigning the json object to a variable. Commented Dec 31, 2015 at 3:30

1 Answer 1

2

I accomplished this using,

gulp.task('concat', function () {
    return paths.concat.forEach(function(obj) {
        return gulp.src(obj.src)
            .pipe(concat(obj.name))
            .pipe(rename(function (path) {
                path.basename += '.min';
                return path;
            }))
            .pipe(gulp.dest('./web/js'));
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.