Creating and deploying Script Applications
This guide will walk you through the process of creating a modern script application for HCL Digital Experience (DX) using the create-dx-script-app tool, and then building and deploying a sample Store Locator Script Application.
Overview
create-dx-script-app is a modular toolkit designed to generate modern React applications that integrate seamlessly with the HCL DX platform. It provides ready-made templates and configurations to accelerate your development workflow.
This tool offers the following key features to streamline your Script Application development and deployment:
- Ready-made React templates built using JavaScript and TypeScript for optimal configuration
- Preconfigured ECMAScript Linter (ESLint), Vite, and Hot Module Replacement (HMR) for rapid development and improved developer experience
- Built-in deployment scripts and HCL DX-specific configurations for seamless integration
- Flexible configuration to support different deployment environments
- Modular architecture that separates core logic from templates for easy maintenance
Prerequisites
Before you begin, make sure you have the following
- Installed Node.js version 20.19 or higher
- Installed Node Package Manager (npm) version 9.6 or higher
- An HCL DX server that is accessible for deployment
Creating a new Script Application
Refer to the following steps to create a new Script Application using the create-dx-script-app tool.
-
Create a new Script Application project using the following command:
npm i @hcl-software/create-dx-script-appThis will launch an interactive wizard that guides you through project creation.
-
Follow the interactive prompts and enter the following details:
- Project name: Choose a name for your application
- Template: Select either JavaScript or TypeScript. TypeScript is recommended for larger projects.
- Additional features: Select optional features you may want for your application
-
After the Script Application is created, configure your environment.
-
Navigate to your project directory using the following command:
cd your-project-name -
Open the
.env.localfile in your project and configure your HCL DX connection settings:# HCL DX connection settings DX_TARGET=http://localhost:10039/wps/portal DX_PROTOCOL=https DX_HOSTNAME=your-dx-hostname DX_PORT=443 DX_USERNAME=your-username DX_PASSWORD=your-password
-
-
Install the required dependencies using the following command:
npm install -
Launch the development server with HMR using the following command:
npm run devYour application will be running at
http://localhost:3000.
Building and deploying the Nex Haven Store Locator sample
The Nex Haven Store Locator sample demonstrates best practices for DX script applications and includes the following features:
- Material UI components
- OpenStreetMap integration
- Interactive store search functionality
- Responsive layout design
- TypeScript and Vite integration
Refer to the following steps to build and deploy the Store Locator sample:
-
Clone the repository using the following command:
gh repo clone HCL-TECH-SOFTWARE/dx-create-script-app cd dx-create-script-app/samples/nex-haven-store-locator-sample -
Install the required dependencies using the following command:
npm install -
Configure your environment by editing the
.env.localfile with your DX server details:-
Navigate to your project directory using the following command:
cd your-project-name -
Open the
.env.localfile in your project and configure your HCL DX connection settings:DX_TARGET=https://your-dx-server.com/wps/portal DX_PROTOCOL=https DX_HOSTNAME=your-dx-hostname DX_PORT=443 DX_USERNAME=your-username DX_PASSWORD=your-password DX_SITE_AREA=/Nex Haven/About Us # Target site area in Nex Haven
-
-
(Optional) Test your application locally before deploying using the following command:
npm run devThis will start a development server with HMR at
http://localhost:3000. -
Build the production-ready bundle using the following command:
npm run buildThis creates optimized files in the
distdirectory. -
Deploy the application to your HCL DX server using the following command:
npm run dx-deployThis command authenticates DXClient's access with your DX server, uploads the built application to the Script Application Library, and places it in the site area specified in your environment configuration.
The deployment process uses DXClient's Script Application deployment capabilities. For more detailed information about DXClient's Script Application commands, options, and requirements, refer to the DXClient Script Application documentation.
Integrating the Store Locator in the Nex Haven site
Note
The Nex Haven site must be available on your DX server. Follow the guide in Create The Sample Site to enable Nex Haven.
Refer to the following steps to integrate the Store Locator sample application in the Nex Haven site in your DX server:
-
Add the Store Locator Script Application to the About Us site area:
- In the Nex Haven site, navigate to the About Us page.
- Toggle Edit Mode to ON.
- Find an appropriate section to add the Store Locator application.
- Drag and drop the deployed Store Locator Script Application.
-
Enhance integration with using the Text Break component:
- Insert a Text Break component from Blueprint components above the Store Locator.
- Configure the following Text Break values:
- Title: Find the nearest store and start exploring
- Subtitle: Select a location from the list, or filter by typing in the field.
- Background color: 241 242 245
- Text color: 28 28 26
- Align: left
-
Toggle Edit Mode to OFF see the fully integrated Store Locator application within your Nex Haven site.
Customizing your Script Application
Proxy Configuration
The generated projects include pre-configured proxy settings to handle API requests during development:
/dx: Routes to the DX portal/api/wcm: Routes to the WCM API
You can customize these settings in your project's vite.config.js/ts file:
'/your-prefix': {
target: 'http://your-target-url.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/your-prefix/, ''),
}
Environment Configuration
If you want to set custom API endpoints using environment variables, run the following commands:
# In .env.local file
DX_TARGET=https://your-dx-server.com/wps/portal
WCM_API_TARGET=https://your-api-server.com/dx/api/wcm/v2/explorer
# Or at runtime
DX_TARGET=https://your-dx-server.com/wps/portal npm run dev
If you want to deploy the Script Application to different environments (dev, test, or prod), run the following command:
# Create environment-specific files (.env.dev, .env.uat, .env.prod)
# Then deploy using:
DX_ENV_FILE=.env.uat npm run dx-deploy
Building and running the tool locally
If you need to customize the create-dx-script-app tool itself, run the following commands:
# Clone the repository
gh repo clone HCL-TECH-SOFTWARE/dx-create-script-app
cd dx-create-script-app/
# Install dependencies and build
npm install
npm run build
npm link
# Now you can run it locally
npm create dx-script-app
Troubleshooting
If you encounter issues during deployment:
- Verify your DX server credentials in
.env.local. - Ensure your DX server is accessible from your development machine.
- Ensure that the site area specified in
DX_SITE_AREAexists on your DX server. - Review the console output for specific error messages.
If you encounter issues during development:
- Verify if your installed Node.js and npm versions meet the requirements.
- Clear your npm cache using the
npm cache clean --forcecommand. - Delete the
node_modulesdirectory and runnpm installagain. - Check your browser console for JavaScript errors.