0

For copying files to destination I am using simple gulp's src and dest

I want to specify this copy action as per key in obj:

    var copy = {
            first: {
                dest: 'dist/index.scala.html',
                src: 'app/index.scala.html'
            },
            second: {
                dest: 'dist/setup.scala.html',
                src: 'app/setup.scala.html'
            }
      };

I am able to create copy task and copy files as per src and dest mentioned in object But I need something like:

    gulp copy:first //this will only copy from src to dest as specifided under 'first' key

    gulp copy:second //this will only copy from src to dest as specifided under 'second' key

Like how we achieve in grunt.

1 Answer 1

1

According to this article "it’s not possible to pass arguments on the command line which can be used by that task".

That said, you can do something like this:

const gulp = require("gulp");

const copy = {
    first: {
        dest: 'dist/index.scala.html',
        src: 'app/index.scala.html'
    },
    second: {
        dest: 'dist/setup.scala.html',
        src: 'app/setup.scala.html'
    }
};

for (let key in copy) {
    gulp.task('copy:' + key, cb => {
        console.log('copy[key]: ', copy[key]);
        cb();
    });
}

Note: I've changed copy = [...] to copy = {...} because arrays can't have strings (such as 'first') as keys but objects can.

Then to run the gulp commands:

gulp copy:first

gulp copy:second

You may also want to have a look at Pass Parameter to Gulp Task.

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.