Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-if

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-if

Conditionally run a task

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
255K
increased by4.49%
Maintainers
1
Weekly downloads
 
Created

What is gulp-if?

The gulp-if package is a conditional plugin for Gulp that allows you to conditionally control the flow of your Gulp tasks. It is particularly useful for running tasks only if certain conditions are met, such as environment variables, file types, or custom logic.

What are gulp-if's main functionalities?

Conditional Task Execution

This feature allows you to conditionally execute tasks based on a condition. In this example, the 'uglify' task is only run if the environment is set to 'production'.

const gulp = require('gulp');
const gulpIf = require('gulp-if');
const uglify = require('gulp-uglify');

const isProduction = process.env.NODE_ENV === 'production';

gulp.task('scripts', function() {
  return gulp.src('src/js/*.js')
    .pipe(gulpIf(isProduction, uglify()))
    .pipe(gulp.dest('dist/js'));
});

Conditional File Handling

This feature allows you to conditionally handle files based on their properties. In this example, the 'cssnano' task is only run on files with a '.css' extension.

const gulp = require('gulp');
const gulpIf = require('gulp-if');
const cssnano = require('gulp-cssnano');
const isCSS = (file) => file.extname === '.css';

gulp.task('styles', function() {
  return gulp.src('src/styles/*')
    .pipe(gulpIf(isCSS, cssnano()))
    .pipe(gulp.dest('dist/styles'));
});

Custom Condition Functions

This feature allows you to use custom functions to determine whether a task should be executed. In this example, files larger than 1MB are renamed with a '-large' suffix.

const gulp = require('gulp');
const gulpIf = require('gulp-if');
const rename = require('gulp-rename');

const isLargeFile = (file) => file.stat.size > 1024 * 1024; // 1MB

gulp.task('rename-large-files', function() {
  return gulp.src('src/files/*')
    .pipe(gulpIf(isLargeFile, rename({ suffix: '-large' })))
    .pipe(gulp.dest('dist/files'));
});

Other packages similar to gulp-if

Keywords

FAQs

Package last updated on 18 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc