babel-plugin-add-module-metadata

raw JSON →
2.32.2 verified Sat Apr 25 auth: no javascript

A Babel plugin for the Liferay ecosystem that scans JavaScript modules for predefined code patterns and adds corresponding metadata entries to the manifest.json file generated by the liferay-npm-bundler. Version 2.32.2 is the latest stable release, maintained as part of the liferay-frontend-projects monorepo with monthly to quarterly releases. Unlike generic Babel plugins, this one is tailored specifically for Liferay's AMD module system, enabling module description prior to load or parse. It is used in conjunction with the Liferay JS Toolkit and npm bundler.

error Error: Cannot find module 'babel-plugin-add-module-metadata'
cause Missing or incorrect installation of the plugin.
fix
Run npm install --save-dev babel-plugin-add-module-metadata and ensure it's in node_modules.
error TypeError: plugin is not a function
cause Passing the plugin string instead of a function in a JavaScript config file that expects function references.
fix
Use the string syntax: plugins: ['add-module-metadata'].
error SyntaxError: Unexpected token 'export'
cause Using ES module syntax in a Babel config file that is treated as CommonJS.
fix
Use module.exports = { plugins: ['add-module-metadata'] }; instead of export default.
gotcha This plugin only works in conjunction with liferay-npm-bundler. Without it, no manifest.json is generated.
fix Ensure liferay-npm-bundler is part of your build process.
gotcha Plugin does nothing if the code does not follow Liferay's AMD module patterns. Standard ES modules are not scanned.
fix Use Liferay.Loader.define or compatible AMD module definitions.
deprecated The older manifest.json format (v1) was deprecated in liferay-npm-bundler v2.0. Newer plugins generate v2 metadata but this plugin may not be updated for v2 format.
fix Check liferay-npm-bundler version. If using bundler v2+, consider migrating to the latest js-toolkit.
npm install babel-plugin-add-module-metadata
yarn add babel-plugin-add-module-metadata
pnpm add babel-plugin-add-module-metadata

Shows minimal .babelrc configuration and the expected transformation from an AMD module to manifest.json metadata.

// .babelrc
{
  "plugins": ["add-module-metadata"]
}

// Example input (to trigger metadata generation):
// file: src/foo.js
Liferay.Loader.define('my-module', ['exports', 'require'], function(exports, require) {
  'use strict';
  exports.default = 'hello';
});

// After building with liferay-npm-bundler, manifest.json will include:
// {
//   "packages": {
//     "my-module": {
//       "metadata": { ... }
//     }
//   }
// }