This website uses cookies to ensure you get the best experience on our website.

Skip to content
LOGO
  • Company

    About IGNEK

    Learn about our story and our mission.

    Careers

    We're hiring!

    We always looking for talented peoples. Join our team!

    Blogs

    The latest industry news, updates and info.

    Case Studies

    Take a closer look at the projects we've delivered

    Webinar

    Watch our latest organized webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Custom Enterprise Portal Development for flawless Solutions

    Dedicated Development Team

    Expand Teams, Optimize Development with Our Expertise

    Back-end Development

    Empowering your digital presence with robust backend development expertise

    Front-end Development

    Crafting engaging user experiences through expert frontend development

    Digital Transformation

    Embrace digital transformation by modernizing process

    SaaS Development

    Transform your business with SaaS Innovative Solutions

    Technologies

    Liferay Services

    Development & Customization

    Theme

    Upgradation

    Migration

    Proof of Concept

    Performance Tunning

    Architecture

    Support & Maintenance

    E-commerce

    Expert Advice

    React Services

    Enterprise Development

    Custom Application

    Single Page Application

    Architecture

    API Integration

    Migration

    Consulting

    Maintenance & Support

    Spring Boot Services

    Web Service

    MVC Web Development

    API Integration

    Security

    Migration

    Microservices

    Support & Maintenance

    AEM Services

    Consulting Service

    Site Development

    Migration & Upgradation

    Integration

    Maintenance & Support

    Custom Solutions

    Content Management

    Team Augementation

  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Transforming industries through cutting edge SaaS solutions.

    Customer Portal : Boost Business Productivity

    Streamline operations and enhance productivity with our Customer Portal solution.

    Liferay Based Intranet Portal

    Internal portal for company communication, collaboration and resources

    Integration

    Matomo Integration with Liferay

    Integrate Matomo to enable user interactions seamlessly.

    Microsoft Teams integration with Liferay

    Integrate to enable seamless collaboration, messaging within your portal.

    Jira Integration With Liferay

    Optimizes business operations by integrating with Jira.

  • Hire Us

    Liferay

    Get expert Liferay developers for seamless portal solutions.

    React JS

    Get expert ReactJS developers for dynamic web solutions.

    Web Developer

    Get custom web solutions from IGNEK's expert developers.

    Spring Boot

    Get top-notch Spring Boot developers for your project success!

    Healthcare

    Get top Healthcare Developers for cutting-edge medical software.

    MERN Stack

    Get expert MERN developers from IGNEK for custom, innovative project solutions.

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • info@ignek.com
    • Ahmedabad, Gujarat, India – 382470
SCHEDULE CALL
  • COMPANY
    • About
    • Case Studies
    • Blogs
    • Career
    • Webinar
  • SERVICES
    • Enterprise Portal Development
    • Dedicated Development Team
    • Back-end Development
    • Front-end Development
    • Digital Transformation
    • SaaS Development
  • SOLUTION
    • Customer Portal:  Boost Business Productivity
    • SaaS : Software as a Service
    • Liferay Based Employee Intranet Portal
  • TECHNOLOGY
    • Liferay Services
      • Liferay Development and Customization
      • Liferay Theme Development Service
      • Liferay DXP 7.4 Upgrade
      • Liferay Migration
      • Liferay Proof Of Concept
      • Liferay Performance Tuning
      • Liferay Architecture Design Service
      • Liferay Support And Maintenance Service
      • Liferay Ecommerce Development
      • Liferay Expert Advice
    • ReactJS Services
      • ReactJS Enterprise Application Development
      • ReactJS Custom Application Development
      • ReactJS Single Page Application Development (SPA)
      • ReactJS Applications Architecture
      • ReactJS API Integration
      • ReactJS Migration
      • ReactJS Consulting
      • ReactJS Maintenance and Support
    • Spring Boot Services
      • Spring Boot Web Development Service
      • Spring MVC Web Development
      • Spring Boot API Integration Service
      • Spring Boot Security
      • Spring Boot Migration Service
      • Spring Boot Microservices
      • Spring Boot Support & Maintenance Service
    • AEM Development Services
      • AEM Consulting Services
      • AEM Site Development
      • AEM Migration & Upgradation
      • AEM Integration Services
      • AEM Maintenance & Support
      • AEM Content Management
      • Custom AEM Solutions
      • AEM Team Augmentation
  • INTEGRATION
  • HIRE US
    • Hire Liferay Developer
    • Hire ReactJS Developer
    • Hire Spring Boot Developer
    • Hire Healthcare Developer
    • Hire Web Developer
    • Hire MERN Stack Developer
  • CONTACT US
  • Company

    About IGNEK

    Careers

    We're hiring!

    Blogs

    Case Studies

    Webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Dedicated Development Team

    Back-end Development

    Front-end Development

    Digital Transformation

    SaaS Development

    Technologies

    Liferay Liferay Services
    • Development & Customization
    • Theme
    • Upgradation
    • Migration
    • Proof of Concept
    • Performance Tuning
    • Architecture
    • Support & Maintenance
    • E-commerce
    • Expert Advice
    React React Services
    • Enterprise Development
    • Custom Application
    • Single Page Application
    • Architecture
    • API Integration
    • Migration
    • Consulting
    • Maintenance & Support
    Spring Boot Spring Boot Services
    • Web Service
    • MVC Web Development
    • API Integration
    • Security
    • Migration
    • Microservices
    • Support & Maintenance
    AEM AEM Services
    • Consulting Service
    • Site Development
    • Migration & Upgradation
    • Integration
    • Maintenance & Support
    • Custom Solutions
    • Content Management
    • Team Augmentation
  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Customer Portal : Boost Business Productivity

    Liferay Based Intranet Portal

    Integration

    Matomo Integration with Liferay

    Microsoft Teams integration with Liferay

    Jira Integration With Liferay

  • Hire Us

    Liferay

    React JS

    Web Developer

    Spring Boot

    Healthcare

    MERN Stack

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • IGNEK
    • Ahmedabad, Gujarat, India – 382470
  • SCHEDULE CALL

Custom Element Using Client Extension

  • Liferay
  • September 23, 2024

Share On :

Introduction

Liferay 7.4 introduced Client Extensions as a powerful way to extend and customize Liferay’s functionalities. Client Extensions are a modern, lightweight approach for front-end development, offering developers the ability to deploy and manage custom UI components, like React Custom Elements, without directly altering Liferay’s core structure. By leveraging these capabilities, developers can create highly dynamic and reusable components that integrate seamlessly into the Liferay ecosystem.

Prerequisites
  • Liferay 7.4 (Community Edition or DXP)
  • Java (JDK 11)
  • Node.js & Yarn
  • Liferay Gradle Workspace 

Note : Liferay uses a Gradle-based workspace to handle builds and package custom elements. This workspace will include all of your customizations and applications that need to be built, tested, and deployed to Liferay.

Implementation of Custom Element Using Client Extensions

Follow the below steps to create a react based custom element using client extension

Step 1 : Setting Up the Liferay Gradle Workspace

The first thing you need is a Liferay Gradle workspace. This workspace contains all necessary configurations and tooling to build and deploy custom elements (like React-based components) as Client Extensions.

Step 2 : Creating a New React Project

For our custom element, we’ll use React to build a component that will be packaged and deployed in Liferay as a Client Extension.

  • First, move into the client-extensions directory within your workspace:
				
					
cd liferay-react-workspace/client-extensions


				
			
  • To create your React project, run the following command using Yarn:
				
					yarn create react-app my-react-app
				
			
image11

Step 3 : Modify the React Project for Liferay

Once you have your basic React project, you need to make some changes so that it works as a custom element within Liferay.

1. Update package.json

The package.json file defines the name and dependencies of your project. One critical update is to ensure the name of the project is unique. Liferay uses custom element names across the platform, so make sure your element doesn’t conflict with others.

  • Open package.json.
  • Update the name field, making it unique:
				
					"name": "my-react-custom-element"
				
			

2. Update index.html

By default, the root element in a React app is rendered into a div with the id root. For Liferay, we need to replace this with a custom tag.

  • Open public/index.html.
  • Replace the following:
				
					
<div id="root"></div>



				
			

    With:

				
					<my-react-custom-element></my-react-custom-element>
				
			

3. Modify React’s Entry Point

React’s default entry point code needs to be adjusted to ensure it behaves like a true custom element that can be added to a Liferay page. We’ll replace the default connection logic with something more dynamic.

  • Open src/index.js.
  • Replace the existing code with the following:
image10
				
					import { render, unmountComponentAtNode } from "react-dom";
import App from "./App";

class WebComponent extends HTMLElement {
  connectedCallback() {
    render(<App />, this);
  }

  disconnectedCallback() {
    unmountComponentAtNode(this);
  }
}

const ELEMENT_NAME = "my-react-custom-element";

if (!customElements.get(ELEMENT_NAME)) {
  customElements.define(ELEMENT_NAME, WebComponent);
}

				
			

First, we create a component called WebComponent, which extends the standard HTMLElement. It uses two key methods: connectedCallback() and disconnectedCallback(). These methods handle the custom React element when it is added or removed from a page.

When the custom element is added, the connectedCallback() method creates a new root element. Then, it uses React to render the application into this new root.

The disconnectedCallback() method runs when the custom element is removed from the page. This unmounts the React component, freeing up memory. Without this, repeated removal and addition of the element would cause memory leaks, eventually leading to browser performance issues.

Finally, we define the React custom element, so when the browser encounters the <my-react-custom-element> tag, it knows to use WebComponent for rendering the application.

Step 4 : Create the client-extension.yaml File

The client-extension.yaml file is what tells Liferay how to treat your React project as a Client Extension. This file is essential for deployment.

  • In your client extension directory, create a file named client-extension.yaml with the following content:
image9
				
					assemble:
    - from: build/static
      into: static
my-react-custom-element:
    cssURLs:
        - css/main.*.css
    friendlyURLMapping: my-react-custom-element
    htmlElementName: my-react-custom-element
    instanceable: false
    name: My React Custom Element
    portletCategoryName: category.client-extensions
    type: customElement
    urls:
        - js/main.*.js
    useESM: true




				
			

This file defines how the custom element is bundled and deployed in Liferay. The urls field points to the generated JavaScript files, and the htmlElementName specifies the custom element tag to be used.

Step 5 : Build and Deploy the Client Extension

Before deploying the client extension we have to give our liferay server’s path so that it directly deployed on server.

First add the server path in liferay.workspace.home.dir

image12
				
					liferay.workspace.home.dir = /home/dell/work/blog/server/liferay-dxp
				
			

Now that your project is ready, it’s time to build and deploy it to Liferay.

  1. Build the Client Extension

Run the following command from your project’s root directory:

image8
				
					./gradlew build -p  ./client-extensions/my-react-custom-element
				
			

This generates a ZIP file in the dist directory containing your React custom element. The file will be named my-react-custom-element.zip.

  1. Deploy the Client Extension

You can now deploy the custom element to your Liferay instance. If you’re running Liferay locally, use the following command:

image1
				
					./gradlew deploy -p ./client-extensions/my-react-custom-element
				
			

This command places the client extension in the correct location (osgi/client-extensions) in Liferay’s bundle for deployment.

Note : Running gradlew deploy will automatically trigger the build process, as the deploy task depends on it. This means you don’t need to run gradlew build separately—gradlew deploy handles both building and deploying in one step.

Note : The -p option in Gradle stands for “project directory.”

For clean deployment, we would generally use the clean task like this:

				
					./gradlew clean deploy -p ./client-extensions/my-react-custom-element
				
			

This command ensures that any previously built files are removed before running a fresh build and deployment.

Conclusion

Whether you’re an experienced React developer building an application for Liferay or a seasoned Liferay developer exploring React, this blog aims to give you the guidance needed to adapt your React app to run seamlessly on Liferay.

Now that your Liferay Gradle Workspace contains your React custom element, you’ll also find other client extensions in the directory, including some built with React and others with Angular. You can explore these examples or keep the workspace focused on your own custom React elements.

Explore Our Services

Discover how we can help your business thrive, whether you’re running a small startup, an SME, or a large enterprise. We’re here to understand your unique needs and goals, offering the expertise and resources to support your journey to success.

Stay informed about our Liferay services and updates by subscribing to our newsletter—just fill in the details below to subscribe.

Loading
Loading...

Related Blogs

July 19, 2023
React with Liferay cover Image
React with Liferay
July 19, 2024
What Is Client Extension & How We Can Use
What Is Client Extension & How We Can Use?
July 19, 2024
Site Initializer Using Client Extension
Site Initializer Using Client Extension
Loading...

Featured Projects Portfolios

March 21, 2024
EPF Government Enterprise Website _ Multilingual, Access for Member, Employer, Corporate - New
EPF Government Enterprise Website : Multilingual, Access for Member, Employer, Corporate

Digital Solutions for Your Business with IGNEK

4.9

5.0

5.0

5.0

LOGO

Making the world a better place through constructing elegant hierarchies

COMPANY

  • About
  • Career
  • Case Study
  • Blogs

SERVICES

  • Enterprise Portal Development
  • Dedicated Development Team
  • Back-end Development
  • Front-end Development
  • Digital Transformation
  • SaaS Development

HIRE US

  • Liferay
  • Spring Boot
  • ReactJS
  • Healthcare
  • MERN Stack
  • AEM

CONTACT

  • info@ignek.com
  • info@ignek.com
SALES
  • sales@ignek.com
  • (+91) 635 157 6580
CAREER
  • hr@ignek.com
  • (+91) 932 849 5160
  • E 910-912, Ganesh Glory 11, Jagatpur Road, SG Highway, Ahmedabad, Gujarat - 382470

© 2018-2025 IGNEK, Inc. All rights reserved

Linkedin Facebook X-twitter Instagram