Reputation: 6353
I have created a simple task that takes an argument:
gulp.task("js", () => {
let stream = gulp
.src("./src/**/*.js", { base: "./src/" })
.pipe($.plumber())
.pipe($.changed("temp"))
.pipe(babel());
// minify is min argument provided
if (args.min == true) stream = stream.pipe($.uglify());
// Update paths
stream
.pipe(
$.preprocess({
context: {
PATH: save.dest,
COMMIT: pkg.version
}
})
)
.pipe(gulp.dest("temp"));
return stream;
});
I want to minify based on whether I'm pushing to QA or PROD:
gulp.task("push-dev", ["js"], function() {})
gulp.task("push-prod", ["js --min"], function() {})
But I get the error:
[11:51:32] Task 'js --min' is not in your gulpfile
Is what I'm trying possible? I'm trying to avoid having to create a whole new task just to handle minification in different environments.
Upvotes: 1
Views: 63
Reputation: 28563
Define your function separately from your task instead of directly in your gulp.task
.
let jsFunc = (doMininfy) => {
let stream = gulp
.src("./src/**/*.js", { base: "./src/" })
.pipe($.plumber())
.pipe($.changed("temp"))
.pipe(babel());
// assuming you meant the parameter to go here?
if (doMininfy) stream = stream.pipe($.uglify());
// Update paths
stream
.pipe(
$.preprocess({
context: {
PATH: save.dest,
COMMIT: pkg.version
}
})
)
.pipe(gulp.dest("temp"));
return stream;
});
gulp.task("js", () => jsFunc());
gulp.task("js-min", () => jsFunc(true));
gulp.task("push-dev", ["js"], function() {});
gulp.task("push-prod", ["js-min"], function() {});
Upvotes: 1