Liferay NPM Bundler Plugin: Inject Imports Dependencies
This is a specialized plugin for the `liferay-npm-bundler`, designed to automate the process of adding dependencies declared as imports within a project's `.npmbundlerrc` configuration directly into its `package.json` file. This streamlines dependency management for Liferay frontend modules, ensuring that all bundled modules are correctly listed as project dependencies, which is critical for Liferay Portal's OSGi-based module system. The current stable version of this plugin is 2.32.2. However, it's crucial to note that its host, `liferay-npm-bundler`, has been officially deprecated as of Liferay 2024.Q4/Portal GA129 and is slated for future removal. This plugin, therefore, is also considered deprecated as it relies entirely on the deprecated bundler's functionality. It served a key role in Liferay's prior frontend development workflow for packaging npm modules into OSGi bundles.
Common errors
-
Plugin 'inject-imports-dependencies' not found or invalid.
cause The plugin name is misspelled in `.npmbundlerrc` or the package was not installed correctly.fixVerify that `liferay-npm-bundler-plugin-inject-imports-dependencies` is listed in your `devDependencies` and that 'inject-imports-dependencies' is correctly spelled in the 'plugins` array within your `.npmbundlerrc` file. Ensure the plugin is placed in the correct `pre-process` or `post-process` phase if specified. -
Declared imports are not being added to package.json dependencies.
cause The `liferay-npm-bundler-plugin-inject-imports-dependencies` plugin might not be correctly activated or there are issues with the `imports` configuration itself in `.npmbundlerrc`.fixEnsure the plugin is correctly listed in the `plugins` array in your `.npmbundlerrc`. Double-check the structure and paths within your `imports` configuration to ensure they are valid and resolvable by the bundler. Check bundler logs for any warnings or errors during the build process.
Warnings
- breaking The underlying `liferay-npm-bundler` (which this plugin extends) has been officially deprecated as of Liferay 2024.Q4/Portal GA129 and is planned for future removal. Liferay is transitioning to standard JavaScript tooling (e.g., esbuild, Webpack, Vite) for frontend development. Using this plugin in new projects or continuing its use in existing projects beyond the stated deprecation timeline will lead to an unsupported and eventually non-functional build process.
- gotcha This plugin is tightly coupled with `liferay-npm-bundler` and the Liferay frontend build ecosystem. Ensure compatibility between the plugin's version, the bundler's version, and your Liferay Portal version to avoid unexpected build failures or incorrect dependency injection.
Install
-
npm install liferay-npm-bundler-plugin-inject-imports-dependencies -
yarn add liferay-npm-bundler-plugin-inject-imports-dependencies -
pnpm add liferay-npm-bundler-plugin-inject-imports-dependencies
Imports
- "inject-imports-dependencies"
import { injectImportsDependencies } from 'liferay-npm-bundler-plugin-inject-imports-dependencies'// In .npmbundlerrc plugins array: { "*": { "plugins": ["inject-imports-dependencies"] } } - No direct CommonJS exports
const injectPlugin = require('liferay-npm-bundler-plugin-inject-imports-dependencies');N/A
- No direct ES Module exports
import * as InjectImportsPlugin from 'liferay-npm-bundler-plugin-inject-imports-dependencies';
N/A
Quickstart
npm install --save-dev liferay-npm-bundler-plugin-inject-imports-dependencies
// Then, create or update your .npmbundlerrc file in your project root:
// (Example showing typical structure and plugin configuration)
{
"*": {
"plugins": [
"inject-imports-dependencies"
]
},
// Example: Define an import that the plugin should inject as a dependency
"imports": {
"some-lcom-module": {
".": "/node_modules/some-lcom-module/index.js"
},
"another-utility": {
".": "/node_modules/another-utility/dist/main.js"
}
}
}