Incorporate gulp-clean-css into the current gulpfile.js

I was recently provided with a gulpfile.js file by a colleague, which contains the code below. It keeps an eye on my scss files and compiles them when I save.

var gulp       = require('gulp'),
gutil      = require('gulp-util'),
browserify = require('browserify'),
uglify     = require('gulp-uglify'),
concat     = require('gulp-concat'),
changed    = require('gulp-changed'),
compass    = require('gulp-compass'),
buffer     = require('vinyl-buffer'),
source     = require('vinyl-source-stream'),
livereload = require('gulp-livereload');

var scssSources = [
        '_src/scss/**/*.scss'
    ],
    jsSources = [
        '_src/js/main.js'
    ],
    jsVendorSources = [
        '_src/js/vendor.js'
    ],
    scriptsPath = 'assets/js',
    scssPath    = 'assets/css';

var onError = function (error)
{
    gutil.log(gutil.colors.red(error));
    this.emit('end');
};

gulp.task('sass', function()
{
    gulp.src(scssSources)
        .pipe(changed(scssPath))
            .on('error', onError)
        .pipe(compass({
            style: 'expanded',
            sass: '_src/scss',
            css: scssPath,
            relative: true,
            require: ['breakpoint', 'susy']
        }))
            .on('error', onError)
        .pipe(gulp.dest(scssPath))
        .pipe(livereload())
});

gulp.task('js', function()
{
    return browserify(jsSources)
            .on('error', onError)
        .bundle()
            .on('error', onError)
        .pipe(source('main.js'))
            .on('error', onError)
        .pipe(buffer())
            .on('error', onError)
        //.pipe(uglify())
          //  .on('error', onError)
        .pipe(gulp.dest(scriptsPath))
        .pipe(livereload());
});

gulp.task('js-vendor', function()
{
    return browserify(jsVendorSources)
            .on('error', onError)
        .bundle()
            .on('error', onError)
        .pipe(source('vendor.js'))
            .on('error', onError)
        .pipe(buffer())
            .on('error', onError)
        //.pipe(uglify())
           // .on('error', onError)
        .pipe(gulp.dest(scriptsPath))
        .pipe(livereload());
});

gulp.task('watch', function()
{
    livereload.listen();
    gulp.watch(['_src/js/main.js', '_src/js/scripts/**/*.js'], ['js']);
    gulp.watch(['_src/js/vendor.js', '_src/js/vendor/**/*.js'], ['js-vendor']);
    gulp.watch(scssSources, ['sass']);
    gulp.watch(['**/*.php', '**/*.html', '**/*.twig']).on('change', function(file) { livereload.changed(file.path) })
});

gulp.task('default', ['watch']);

Thinking about improving and simplifying things, I now want to compress my CSS output using "gulp-clean-css" npm package (https://www.npmjs.com/package/gulp-clean-css). How should I integrate this into the existing gulpfile shown above?

I have already navigated to my Wordpress theme directory and executed

npm install gulp-clean-css --save-dev
- is it correct to assume I just need to insert the necessary code somewhere in here?

If further information is needed, please let me know.

Warm regards,

Oliver

Answer №1

Just found out I can switch the style from 'expanded' to 'compressed'. Wow! Sharing this in case it benefits someone else!

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

Site Having Trouble Displaying Image

I'm currently working on a Bridgetown website using Bootstrap 5, and I've encountered an issue with adding an image that won't show up on the site. This is what it currently looks like: https://i.sstatic.net/IUR7x.jpg Code <nav class=&quo ...

What is causing the CSS3 tabbed area to be restricted?

Experimenting with CSS tabs found at http://css-tricks.com/examples/CSSTabs/: Sample six .w3c { min-height: 250px; position: relative; width: 100%; } .w3c > div { display: inline; } .w3c > div > a { margin-left: -1px; position: relative; left: 1 ...

``A problem with the background image of the left panel in Framework 7

After setting a background image for the side panel and blurring it using CSS, I encountered an issue where the text and icons within the side panel also became blurred. Despite attempting to isolate the background image in a separate class, the problem ...

What is the best way to create transparency within an icon's background without affecting the surrounding box?

Is there a way to set the background color of the icon inside the circle without affecting the transparent box around it? Currently, when I use background:white, it changes both the circle and the surrounding box. ...

Tracking your Mongoose Connections

I'm currently working on implementing a following/followers feature for a nodejs/mongoose website. The issue I'm facing involves storing IDs properly using the methods below. It seems like only the ID is being saved correctly in the 'followi ...

Overflow issue with Bootstrap 4 Navbar collapse and Express/Node partial

Hey everyone, I'm currently facing an issue with the navbar collapse feature from Bootstrap and could really use some help. My tech stack includes Express, Node, and Handlebars, where the header is a partial. The problem I'm encountering is that ...

Accessing information from MongoDB with Node.js and Express

I have a mongodb database with 4 collections. Currently, I retrieve data from each collection individually. How can I retrieve data from different collections in the same code using keywords like findOne and getAll? My model.js file is provided below. The ...

ObjectArray in Node.js

Building an object array in my node app involves transforming another object array. Let's assume the initial object array is structured like this... levels: [ { country_id: 356, country_name: "aaa", level0: "bbbb", level1: "cccc", level2: "dddd", le ...

Querying a Mongoose database using ObjectID references

I am working with two schemas: let adSchema = mongoose.Schema ( { author: {type: ObjectId, ref: 'User'}, title: {type: String, required: true }, town: {type: ObjectId, ref: 'Town', required: true}, } ...

What is the best way to extract image data from a JSON response received from an API call?

For my WordPress plugin, I decided to experiment by creating one that retrieves the Astronomy Picture of the Day from the NASA Open API. After successfully fetching the image, my next challenge arises - what do I do next? It seems like I need to parse th ...

Sophisticated SQL query that computes the sum of multiple columns' values

I have a database table named music_lib with numerous columns and over 2000 records. id | track_id | total_plays | total_downloads | likes | active | etc | etc My goal is to retrieve the latest 50 active records based on the id field but ordered by the s ...

Breakpoint for mobile menu in FoundationCSS

When the browser is resized, the mobile menu appears at 568x320, which is the default breakpoint. I would like to create a breakpoint around 900px to address the issue with the menu being too large as shown in the image below. However, I am unsure of how ...

Transforming a string that represents an array into an actual array using JavaScript

Currently, I am working on a project that involves the use of MySQL, React, and Express.js. One issue I have encountered is the need to save an array into MySQL. However, there seems to be no direct way to do this, so I had to convert the array into a st ...

What are the ways to recognize various styles of handlebar designs?

Within my project, I have multiple html files serving as templates for various email messages such as email verification and password reset. I am looking to precompile these templates so that they can be easily utilized in the appropriate situations. For ...

Guide to using GCP CloudStore API

Encountering an error while using REST Reference in Node.js Google Cloud Store. When testing in Postman, the following error occurred. URL: {projectId}:allocateIds Request Body: { "keys": [ { "partitionId": { "namespaceId": "default", "proj ...

Applying CSS to inherit styles

I have a group of divs with a similar style, but each one has different padding and margin settings. Here is an example: <div class="mainStyle" id="cc">CC</div> <div class="mainStyle" id="bb">BB</div> <div class="mainStyle" id=" ...

Sending handlebars variable to the client-side JavaScript file

I am currently working on an application using node.js along with express and handlebars, and I'm trying to find a way to transfer handlebars data from the server to client-side JavaScript files. Here is an example: //server.js var person = { na ...

What steps are involved in hosting nodejs services on an nginx server within a Virtual Machine?

After creating some nodejs services on my Ubuntu local machine, I am now looking to deploy them onto an nginx server in a separate VM. I have successfully set up the nginx on the virtual machine, but I am unsure how to transfer my nodejs services to the ...

I encountered an issue when installing npm modules as I tried using all the available registry commands but still

I'm encountering an issue with npm install and have attempted various registry commands, but I still can't resolve the problem. npm timing stage:rollbackFailedOptional Completed in 0ms npm timing stage:runTopLevelLifecycles Completed in 210 ...

The external Jquery file is being successfully loaded, however, the Jquery functions are failing to execute

I'm having an issue with my HTML partial, main index.html, and external JQuery file. Even though the file is being loaded successfully (verified through an alert function), the JQuery functions are not executing as expected. Upon checking the resourc ...