将参数发送给吞咽任务 [英] Send arguments to gulp task
问题描述
关于这个主题,还有其他一些关于stackoverflow的问题,但不是我期待的那个。
以下是我的gulpfile.js的简化版本
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('css',function(){
gulp.src('site / scss / style.scss')
.pipe(sass())
.pipe(gulp.dest('assets / css'))
});
$ b gulp.task('watch',function(){
gulp.watch('site / scss / ** / *。scss',['css']);
});
我可以成功地做到这一点:
gulp手表
现在我希望能够在我的终端命令行中做到这一点:
gulp watch my-domain -name
或
gulp watch my-other-domain
大脑看起来像这样:
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('css',function(name){
gulp.src('site / scss / style.scss')
.pipe(sass())
.pipe(gulp.dest('assets / css'))
});
$ b $ gulp.task('watch',function(name){
gulp.watch('site / scss / ** / *。scss',['css',name]) ;
});
我尝试发送名称
作为我的手表任务的变量。在我的情况下,它会是 my-domain-name
或 my-other-domain
,这取决于我在我的终端。
如何从终端发送参数到watch任务,然后转到css任务?
有许多来源将参数从命令行传递给gulp。请参阅:
https: //www.sitepoint.com/pass-parameters-gulp-tasks/
https://github.com/gulpjs/gulp/blob/master/docs/recipes/pass-arguments -from-cli.md
官方配方使用
minimist 一个非常流行的软件包。
因此,通过这些方法,您不会将命令行参数直接传递给观看任务,而是指向任何任务可以访问的对象。
它看起来像 gulp-param 可以按你的意思做任何事情,直接在每个任务的回调函数中注入命令行参数。
There are other questions on stackoverflow about this topic, but not the one I was hoping for.
Here is a simplified version of my gulpfile.js
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('css', function() {
gulp.src('site/scss/style.scss')
.pipe(sass())
.pipe(gulp.dest('assets/css'))
});
gulp.task('watch', function() {
gulp.watch('site/scss/**/*.scss', ['css']);
});
I can do this successfully:
gulp watch
Now I want to be able to do something like this in my terminal command line:
gulp watch my-domain-name
or
gulp watch my-other-domain
My gulpfile would in my mind look something like this:
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('css', function(name) {
gulp.src('site/scss/style.scss')
.pipe(sass())
.pipe(gulp.dest('assets/css'))
});
gulp.task('watch', function(name) {
gulp.watch('site/scss/**/*.scss', ['css', name]);
});
I try to send name
around as a variable of my watch task. In my case it would be my-domain-name
or my-other-domain
depending on what I write in my terminal.
How can I send a parameter from the terminal to the watch task and then over to the css task?
There are a number of sources for passing parameters from the command line to gulp. See:
https://www.sitepoint.com/pass-parameters-gulp-tasks/
https://github.com/gulpjs/gulp/blob/master/docs/recipes/pass-arguments-from-cli.md
The official recipe uses minimist an extremely popular package.
So with these approaches you would not be passing the command line args directly to the watch task, but rather to an object that can be accessed by any task.
And it look like gulp-param may do exactly what you want, directly injecting command line args into each task's callback function.
这篇关于将参数发送给吞咽任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!