What is the most efficient approach to managing multiple projects using a single gulp task?

I am currently working on managing multiple themes using a single gulp.js file.

// Optimize images
gulp.task('images', function () {

  // Loop through different themes to optimize images
  var themes = ['palo','alto'];
  
  for (var i = 0; i < themes.length; i++) { 
    return gulp.src(themes[i]+'/images/**/*')
      .pipe($.cache($.imagemin({
        progressive: true,
        interlaced: true
      })))
      .pipe(gulp.dest('dist/'+themes[i]+'/images'))
      .pipe($.size({title: 'images'}));
 }

});

Instead of creating separate blocks for each theme, I prefer to iterate through an array of themes in the gulp task.

Answer №1

To optimize image processing tasks, utilize a stream array:

 var es = require('event-stream');

 ...


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

    var themes = [
        {
            src: 'palo/images/**/*',
            dest: 'dist/palo/images'
        },
        {
            src: 'alto/images/**/*',
            dest: 'dist/alto/images'
        }
    ];

    var tasks = themes.map(function(theme) {
        return gulp.src(theme.src)
            .pipe($.cache($.imagemin({
                progressive: true,
                interlaced: true
            })))
            .pipe(gulp.dest(theme.dest))
            .pipe($.size({title: 'images'}));
    })

    return es.merge.apply(null, tasks)

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Refresh data on Table with AJAX and a repeated process

I am relatively new to Javascript and Ajax, so please bear with me as I explore... My goal is to update a table after inserting a new row. Instead of generating an entire HTML table through Ajax output, I would prefer to gather data from a PHP MySQL datab ...

Display the scrollbar in a Boostrap CSS table when the content exceeds the height of the div

I've been working on a Bootstrap page that looks like this: https://i.sstatic.net/kpHMM.png On the right side, there are two tables inside a div. The issue I'm facing is that when the tables contain too many elements, they grow in height instea ...

Can React Slick be configured to display a Carousel within another Carousel?

Can React Slick support a Carousel within another Carousel? import Slider from "react-slick"; <Slider {...settings} > <div/> <div> <Slider {...settings} > ...

Is there a way to link a SQLite local database with an HTML frontend?

After transitioning my basic database from Ms Access to SQLite for the sake of having an open source option, I am now challenged with developing a visual data entry form for this database. A similar query (HTML/JS as interface to local SQLite database) ou ...

The clientWidth and scrollWidth properties will constantly be the same

I am currently utilizing Vuetify text-fields and aiming to exhibit a tooltip showcasing the content only if it exceeds the field width (requiring user scroll). The tooltip should solely be visible on hover, as per default behavior. My initial approach ensu ...

Obtaining page information from a frame script in e10s-enabled Firefox: A guide

One of the challenges I'm facing is with my Firefox extension, where a function loads page information using the following code: var title = content.document.title; var url = content.document.location.href; However, with the implementation of multi- ...

I'm encountering an issue where the database table in Postgres is not updating correctly while working with Node

Currently, I am working on a CRUD application where I can successfully read and delete data from the database table. However, I have encountered an issue when trying to update specific data for a particular route. Every time I attempt to update the data in ...

Can I use more than one AudioContext at a time?

In my project, I am developing a React App using MeteorJS that utilizes the Web Audio API. This app consists of multiple pages, each of which utilizes web audio functionality. The issue I am facing is that I have hit the limit of 6 audio contexts allowed i ...

Looking for a method to select a random value from an array of objects without having to go through the entire parent array?

As a JavaScript newcomer, I am seeking assistance with a particular task. The array of objects in question looks like this: const data = { "Total_packages": { "package1": { "tags": [ "kj21", ...

Mastering the complexities of Javascript, AJAX, and PHP intertwined

Hello everyone, I'm currently working on a website in Codeigniter and I have a form that I submit using PHP, which works perfectly. However, I also have a small dropdown menu on the side of my page that allows users to jump between pages by clicking o ...

I am unable to pass a variable through a callback, and I cannot assign a promise to a

Currently, I am facing a challenge with my code where I need to loop through a hard-coded data set to determine the distance from a user-entered location using Google's web API. The issue lies in passing an ID variable down through the code so that I ...

Create a background for a dropdown list that appears unreachable, positioned above all other elements

I am encountering an issue with my autocomplete function where the drop down list appears unreadable as it is overlapping other elements on the page. The problem lies in the fact that I did not manually create the drop down list, but rather it is generate ...

Is it feasible to initiate an AJAX request without expecting a response?

Can a jQuery.ajax call or similar be sent without expecting a response? I need to execute a server-side action when leaving the page using the onbeforeunload command, but I do not require any feedback to the client. I only want to trigger the command and n ...

What sets apart the two syntaxes for JavaScript closures?

Similar Query: Is there a distinction between (function() {…}()); and (function() {…})();? I've come across a way to prevent variables from becoming global by using the following syntax: (function ($, undefined) { })(jQuery); Rec ...

What is the best way to create a countdown timer with React

I've been attempting to create a countdown timer using React. The goal is to count down from 10 to 0 and then trigger a function once it reaches 0. After some searching, I came across an example that seemed ideal for me: https://codesandbox.io/s/0q45 ...

Introducing a content height offset to create a smooth slide-up animation on hover

How can I offset a block with a title and description above a picture by the height of the description content? See the example picture below: https://i.sstatic.net/DzcMo.png The goal is to have both titles visible by default, but when hovering over the ...

Is there a way to configure the Bootstrap Table plugin to automatically set a search string when it is first loaded?

When using the Bootstrap Table plugin, how can you specify a search string to be preloaded when the table is first loaded? The plugin documentation (available at ) mentions a "data-search" attribute for enabling the search input, but it does not explain ho ...

Angular JS - Implementing a flexible URL structure for fetching data using $http GET

I have been working on implementing a login feature for my app by using a custom REST API. Initially, I was able to successfully authenticate by manually entering the complete URL with the username and password: http://www.myexample.com/ACTION/USER/PASSWO ...

The Node.js EventEmitter encounters an error stating `listener must be a function` when the `typeof` operator indicates that the value is a function, hint

Dealing with an object that is being interacted with by multiple node.js modules has presented some challenges. My goal is to allow certain modules to add eventListeners to the object. In my codebase, I have an events file where event emitters are attach ...

I successfully created a Chinese writing practice deck in Anki, which is functional on the desktop version but unfortunately not compatible with Ankidroid

While AnkiDesktop is functioning properly, there seems to be an issue with character encoding in Ankidroid. Despite trying numerous solutions, the problem persists. The character length displays correctly in Anki Desktop, but not in Ankidroid. For example ...