The `liferay-npm-bundler-plugin-create-react-app` is a specialized plugin designed to facilitate the integration of projects bootstrapped with Create React App (CRA) into the Liferay Portal environment. It works in conjunction with `liferay-npm-bundler` to transform standard CRA output into OSGi bundles, making them deployable as Liferay widgets or portlets. This plugin manages the necessary adaptations for module loading, asset paths, and other build configurations specific to Liferay's ecosystem, which typically relies on an AMD loader. While the current stable version is 2.14.1, the underlying `liferay-npm-bundler` toolset is deprecated as of Liferay 2024.Q4 (Portal GA129) and is planned for future removal, meaning this plugin is primarily relevant for older Liferay DXP/Portal versions. Its key differentiator is simplifying the process of making CRA projects compatible with Liferay's unique bundling requirements without extensive manual configuration.
npm install liferay-npm-bundler-plugin-create-react-appVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to enable the `create-react-app` plugin in a `.npmbundlerrc` file for Liferay's npm bundler to process a Create React App project.
For new projects or migration, consult Liferay's official documentation on Client Extensions and modern front-end development practices. For existing projects, be aware that active support for this bundling approach may cease in future Liferay versions. Plan for migration.
Always use `npm` as your package manager when developing Liferay React applications to avoid potential bundling conflicts and runtime errors with React hooks. Delete `node_modules` and `package-lock.json`, then reinstall with `npm install`.
Ensure that your `index.js` (or primary entry point) explicitly imports at least one CSS file, even if it's an empty one, to satisfy the plugin's expectations and generate the necessary static CSS output.
Align your project's React version and JSX runtime configuration with Liferay's recommendations for your specific DXP version. If using newer React versions, carefully manage externalized dependencies and consider Liferay Client Extensions for more isolated and independent bundling.
Switch your project's package manager from `yarn` to `npm`. Delete your `node_modules` directory and `package-lock.json` (if present), then run `npm install` to ensure a single, consistent React installation.
Ensure that your Create React App project's main entry point, typically `src/index.js`, includes an explicit import statement for a CSS file (e.g., `import './index.css';`). This will trigger CRA to generate the expected CSS bundle that the Liferay bundler plugin anticipates.