If Gulp is running continuously, what output will I receive?

After reading a helpful post on StackOverflow about gulp tasks (viewable here), I came to the conclusion that it's not advisable to omit returning anything in a gulp task. For proper synchronization of asynchronous tasks, the caller should wait.

Presently, my gulpfile.js appears as follows:

'use strict';

var gulp = require('gulp'),
    uglify = require('gulp-uglify'),
    livereload = require('gulp-livereload'),
    del = require('del'),
    util = require('gulp-util'),

    paths = {
        scripts: {
            main: 'app.js',
            controllers: 'controllers/*.js',
            services: 'services/*.js'
        },
        css: 'css/*.css',
        html: {
            index: 'index.html',
            views: 'views/*.html',
            directives: 'directives/*.html'
        },
        bower_components: 'bower_components/*.*'
    };

gulp.task('build-js', function() {
    var destination;

    for (var key in paths.scripts) {
        util.log('Building ' + key);

        if (/\*\.js$/.test(paths.scripts[key])) { 
            destination = 'build/' + paths.scripts[key].slice(0, -4);
        } else {
            destination = 'build/';
        }

        gulp.src(paths.scripts[key])
            .pipe(uglify())
            .pipe(gulp.dest(destination));
    }

    util.log('returning..');

    return;

});

I am uncertain about what should be returned within my build-js task.

What is considered the best practice in this scenario? Installing an additional module to address this issue isn't something I wish to do.

Any guidance on how to proceed would be greatly appreciated!

Answer №1

Gulp automates the process of iterating over files without the need for manual looping. To incorporate conditional operations, gulp-if can be used. Here is a simplified example:

gulp.task('build-js', function() {
    var destination;

    return gulp.src(paths.scripts)
            //.pipe(gulp-if(....))
            .pipe(uglify())
            .pipe(gulp.dest(destination));
    }

});

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

Tips for effectively highlighting search text within HTML content without causing any issues

I am in search of a solution that can assist me in searching for specific terms within an HTML string while also highlighting them. I have the ability to remove the HTML content from the string, but this poses the problem of losing the context of the origi ...

Circular graphs displaying percentages at their center, illustrating the distribution of checked checkboxes across various categories

Looking for a JavaScript script that displays results in the form of circles with percentage values at their centers, based on the number of checkboxes checked in different categories. The circle radius should be determined by the percentage values - for e ...

Having trouble terminating the session with the authentication provider SSO on Node JS

I'm struggling with ending the session properly when a user makes a request to my /logout endpoint. I want to clear the session and require the user to log in again via SSO. Currently, after an initial login, I remain logged in without needing to re-e ...

Unable to adjust layout when code is functioning alongside background-color

I'm looking to dynamically change the position of an item on my webpage when it is clicked. Is there a way I can achieve this without relying on id names? I currently have a code snippet that successfully changes the background color, but for some rea ...

In Node.js, when accessing a Firebase snapshot, it may return a

Currently, I am utilizing Firebase functions to execute the code for my Flutter application. This code is responsible for sending push notifications to my app. However, I am encountering an issue where I receive a null value at snap.val(). Take a look at h ...

Loop through an array of div IDs and update their CSS styles individually

How can I iterate through an array of Div IDs and change their CSS (background color) one after the other instead of all at once? I have tried looping through the array, but the CSS is applied simultaneously to all the divs. Any tips on how to delay the ...

JavaScript and DOM element removal: Even after the element is removed visually, it still remains in the traversal

Our goal is to enable users to drag and drop items from a source list on the left to a destination list on the right, where they can add or remove items. The changes made to the list on the right are saved automatically. However, we are encountering an iss ...

Sending a jsp page for review at specified intervals

Using the setTimeout method, I attempted to achieve this. I passed a variable containing time as an argument, but the setTimeout method is only taking the initialized value of that variable and not the updated value fetched from the database. Below is the ...

Having difficulty executing the npm test command for my Angular 2 application

I am currently working on an Angular 2 application, and I am fairly new to it. I have set it up with Cordova app and run it through npm. The app starts without any errors and runs smoothly. However, when I try to run the tests using node (i.e., npm test), ...

What is the process of transferring data from one div to another div (table) using AngularJS?

In my quest to enhance my table with JSON data upon clicking the + icon, I am faced with two sections: Pick Stocks where stock names and prices (retrieved from data.json) need to be added to the table found in the Manage Portfolio section. First Section h ...

How to display 3 items per row in a React table by utilizing a map function loop

Currently, my table using material UI generates one column on each row. However, I would like to display 3 columns as items on each row. Below is the mapping for my table: <TableBody> {this.props.data.slice(page * rowsPerPage, page * rowsPerPage ...

How can I redirect to another page when an item is clicked in AngularJS?

Here is an example of HTML code: <div class="item" data-url="link"></div> <div class="item" data-url="link"></div> <div class="item" data-url="link"></div> In jQuery, I can do the following: $('.item').click ...

The complete page gets re-rendered when Nuxt child routes are used

When I attempt to utilize child routes, my goal is to maintain specific data on the page while modifying other content. To illustrate this concept, I have created a straightforward example available at this link. After selecting "cat" and increasing the ...

Sort through data based on specific data fields upon the button click event using JSON and Vue.js

Is there a way to use JSON files in Vue.js to filter data based on category when a button is pressed? I have objects with categories inside the data. portfolio-v1.json { "data":[ { "image_path":"static/products/DEL ...

Angular 4: Unhandled error occurred: TypeError - X does not exist as a constructor

I am currently developing a project in Angular 4, and I encountered an error while running the application. The specific error message is as follows - ERROR Error: Uncaught (in promise): TypeError: index_1.EmployeeBase is not a constructor TypeError: in ...

Displaying the URL of a link on the screen using jQuery

I am looking for a solution to add a link address after the link itself in a table containing reference links for our staff. I have used CSS to achieve this in the past, but the address was not copyable by users. Instead, I am interested in using jQuery&ap ...

Eliminate repetitive elements within an array of objects

Is there a way to eliminate duplicate values in an object array using Javascript? 0: {d: “2021/01/19”, color: “#009988"} 1: {d: “2021/01/19”, color: “#CC3311"} 2: {d: “2021/01/19”, color: “#009988"} 3: {d: “2021/01/19”, ...

What steps can I take to resolve the CLIENT_MISSING_INTENTS issue?

After diving into learning about discord.js, I've run into a bit of a roadblock. Despite trying to troubleshoot by searching online, I can't seem to resolve the issue. const Discord = require('discord.js'); // const Discord = require(&a ...

Ways to verify if the user has inputted a typeahed value

My code snippet looks like this: var students = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('fullName'), queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { ...

What is the reason file inputs do not trigger 'input' events, while 'change' events do fire?

Trying out a basic input: <input type="file"/> Noticing that the input event doesn't trigger when a new file is selected: $('input').on('input', function(event){ console.log('input value changed', event.targe ...