Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure tasks #120

Closed
yrezgui opened this issue Jan 9, 2014 · 15 comments
Closed

Configure tasks #120

yrezgui opened this issue Jan 9, 2014 · 15 comments

Comments

@yrezgui
Copy link

yrezgui commented Jan 9, 2014

Hi guys,
I just switched from Grunt and I find with gulp, that there is no way to configure tasks. I know gulp hasn't the same philosophy as Grunt but I have some cases where I need to run tasks but with different configurations while I don't want to copy paste code too.

Can you help me ?

@dashed
Copy link
Contributor

dashed commented Jan 9, 2014

May be related to robrich/orchestrator#17

What exactly are you trying to do?

@yrezgui
Copy link
Author

yrezgui commented Jan 9, 2014

For example, I want this task to have parameters for the different folders used.

gulp.task('scripts', config, function() {
  // Minify and copy all JavaScript (except vendor scripts)
  return gulp.src(config.patternFiles)
    .pipe(uglify())
    .pipe(gulp.dest(config.destinationPath));
});

gulp.task('dev', function () {

  gulp.run('scripts', {
    patternFiles: ['dev/desktop/js/**/*.js', '!dev/desktop/js/vendor/**'],
    destinationPath: 'build/desktop/js'
  });

  gulp.run('scripts', {
    patternFiles: ['dev/mobile/js/**/*.js', '!dev/mobile/js/vendor/**'],
    destinationPath: 'build/mobile/js'
  });
});

What do you think about it (just idea of the possible code, doesn't work obviously) ?

@dashed
Copy link
Contributor

dashed commented Jan 9, 2014

My usual work around for this kind of thing is that, since it's javascript, you can wrap a function:

var do_stuff = function(config) {
  return gulp.src(config.patternFiles)
    .pipe(uglify())
    .pipe(gulp.dest(config.destinationPath));
}

gulp.task('dev', function () {

do_stuff({
    patternFiles: ['dev/desktop/js/**/*.js', '!dev/desktop/js/vendor/**'],
    destinationPath: 'build/desktop/js'
  });

do_stuff({
    patternFiles: ['dev/mobile/js/**/*.js', '!dev/mobile/js/vendor/**'],
    destinationPath: 'build/mobile/js'
  });
});

@stryju
Copy link
Contributor

stryju commented Jan 9, 2014

also, you can export some settings to json files and just require them, like


config.json

{
  "desktop" : {
    "src" : [ "dev/desktop/js/**/*.js", "!dev/desktop/js/vendor/**"],
    "dest" : "build/desktop/js"
  },
  "mobile" : {
    "src" : [ "dev/mobile/js/**/*.js", "!dev/mobile/js/vendor/**"],
    "dest" : "build/mobile/js"
  }
}

gulpfile.js

// ...
var config = require('./path/to/config.json');

function doStuff(cfg) {
  return gulp.src(cfg.src)
    .pipe(uglify())
    .pipe(gulp.dest(cfg.dest));
}

gulp.task('dev', function () {
  doStuff(config.desktop);
  doStuff(config.mobile);
});

@dashed
Copy link
Contributor

dashed commented Jan 9, 2014

@stryju nice! i hadn't thought of that one.

@stryju
Copy link
Contributor

stryju commented Jan 9, 2014

@dashed thanks!
what's more - now you can use the same config in both - grunt AND gulp ;-)


@yrezgui does this answer your question?

@dashed
Copy link
Contributor

dashed commented Jan 9, 2014

@travm Consider #120 (comment) to include to the frontend book?

@stryju
Copy link
Contributor

stryju commented Jan 9, 2014

@dashed @travm oh cool!

i did a thing! look 'ma! i'm helping! i'm helping! 😊

@dashed
Copy link
Contributor

dashed commented Jan 9, 2014

@stryju
Copy link
Contributor

stryju commented Jan 9, 2014

had a quick look and it looks like some1 tackled that topic already (in grunt section, so still a valid suggestion to use it in gulp as well) ;-) tooling/book-of-modern-frontend-tooling#2 (comment)

@yrezgui
Copy link
Author

yrezgui commented Jan 9, 2014

Thanks guys. I thank about a similar way. I just wanted to know if gulp maybe think about an integration directly in the tasks. Let's use that for now 😃

@yrezgui
Copy link
Author

yrezgui commented Jan 9, 2014

I close the issue. Maybe adding @stryju idea to a best practises wiki page ?

@stryju
Copy link
Contributor

stryju commented Jan 9, 2014

PR ready ;-)

@travm
Copy link

travm commented Jan 9, 2014

@dashed @stryju Nice! It would be a great addition!

@dashed
Copy link
Contributor

dashed commented Jan 9, 2014

@travm note compatibility with grunt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants