Legacy Knowledge Base
Published Jun. 30, 2025

How to minify the CSS and Javascript resources by customization

Written By

Anushka Tiwari

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • How to perform the minification of the CSS and Javascript resources by using the Liferay theme builder.

Environment

  • Liferay DXP 7.4

Resolution

  • How to make Gradle call gulp build in themes

    Essentially, the idea is to replace the Gradle theme build process with gulp, which should make it very similar, if not identical, to the node.js version of the build process.

    1. Create an empty folder somewhere on the file system.
    2. In this empty folder, follow all the instructions from Setting Up an Environment and Creating a Theme up through the yo liferay-theme step, making sure to specify the same theme name and theme base as the Gradle-based theme you originally created.
    3. Copy the following files from the generated theme to your Gradle-based theme.
      • liferay-theme.json
      • package.json
      • package-lock.json
    4. Create a new file gulpfile.js at the top level of your Gradle-based theme that it contains the following:
    'use strict';
    
    var gulp = require('gulp');
    var liferayThemeTasks = require('liferay-theme-tasks');
    
    liferayThemeTasks.registerTasks({
     gulp: gulp,
     pathDist: 'build/libs/',
     pathSrc: 'src/main/webapp/'
    });
    • when installing the Liferay theme generator, built via gulp directly. Then, add the below line to the gulp.js file at the beginning of the file:
       
    process.env.NODE_ENV = 'production';
    • Add the following to the end of your document build.gradle, which will do the following:
      • ensure that the NODE_ENV the variable is set to production so that gulp build minifies CSS
      • replace the buildCSS task with an invocation to gulp build
      • clear the actions in the war task since we already generated a war with gulp build
    apply plugin: "com.liferay.node"
    tasks.getByPath('packageRunBuild').configure {
    environment "NODE_ENV", "production"
    }
    tasks.getByPath('buildCSS').configure {
    actions.clear()
    finalizedBy packageRunBuild
    }
    tasks.getByPath('war').configure {
    actions.clear()
    }
    • Run blade gw deploy as normal.

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base