Gulp doesn't offer any kind of util for that, but you can use one of the many command args parsers.
(Gulp不提供任何类型的util,但你可以使用众多命令args解析器之一。)
I like yargs
.(我喜欢yargs
。)
Should be:(应该:)
var argv = require('yargs').argv;
gulp.task('my-task', function() {
return gulp.src(argv.a == 1 ? options.SCSS_SOURCE : options.OTHER_SOURCE)
.pipe(sass({style:'nested'}))
.pipe(autoprefixer('last 10 version'))
.pipe(concat('style.css'))
.pipe(gulp.dest(options.SCSS_DEST));
});
You can also combine it with gulp-if
to conditionally pipe the stream, very useful for dev vs. prod building:
(您还可以将它与gulp-if
以有条件地管道流,对于dev与prod构建非常有用:)
var argv = require('yargs').argv,
gulpif = require('gulp-if'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify');
gulp.task('my-js-task', function() {
gulp.src('src/**/*.js')
.pipe(concat('out.js'))
.pipe(gulpif(argv.production, uglify()))
.pipe(gulpif(argv.production, rename({suffix: '.min'})))
.pipe(gulp.dest('dist/'));
});
And call with gulp my-js-task
or gulp my-js-task --production
.
(并使用gulp my-js-task
或gulp my-js-task --production
调用。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…