AMDローダー構成のエクスポート方法
Liferay npm バンドラーは Liferay 2024.Q4/Portal GA129 で廃止され、将来削除される予定です。
Liferay AMD Loader が内部でどのように動作するのか分からない場合は、まず Liferay AMD Module Loader をお読みください。
重複排除 が実施されると、 /o/js_loader_modules URLによって返される構成を通じて、JavaScriptモジュールがLiferay AMD Loaderで使用できるようになります。
この記事では、以下に示す OSGi バンドルを参照として使用します。
my-bundle/META-INF/resources/package.json- name: my-bundle-package
- バージョン:1.0.0
- main: lib/index
- 依存関係:
- isarray:2.0.0
- isobject: 2.1.0
- …
lib/index.js- …
- …
node_modules/isobject@2.1.0/package.json- name: isobject
- バージョン:2.1.0
- main: lib/index
- 依存関係:
- isarray: 1.0.0
- …
- …
isarray@1.0.0/package.json- name: isarray
- バージョン:1.0.0
- …
- …
isarray@2.0.0/package.json- name: isarray
- バージョン:2.0.0
- …
- …
たとえば、上記の構造の場合、 OSGi バンドルと npm パッケージ構造で説明されているように、Liferay AMD ローダーが使用できるように以下の構成が公開されています。
Liferay.PATHS = {
...
'my-bundle-package@1.0.0/lib/index': '/o/js/resolved-module/my-bundle-package@1.0.0/lib/index',
'isobject@2.1.0/index': '/o/js/resolved-module/isobject@2.1.0/index',
'isarray@1.0.0/index': '/o/js/resolved-module/isarray@1.0.0/index',
'isarray@2.0.0/index': '/o/js/resolved-module/isarray@2.0.0/index',
...
}
Liferay.MODULES = {
...
"my-bundle-package@1.0.0/lib/index.es": {
"dependencies": ["exports", "isarray", "isobject"],
"map": {
"isarray": "isarray@2.0.0",
"isobject": "isobject@2.1.0"
}
},
"isobject@2.1.0/index": {
"dependencies": ["module", "require", "isarray"],
"map": {
"isarray": "isarray@1.0.0"
}
},
"isarray@1.0.0/index": {
"dependencies": ["module", "require"],
"map": {}
},
"isarray@2.0.0/index": {
"dependencies": ["module", "require"],
"map": {}
},
...
}
Liferay.MAPS = {
...
'my-bundle-package@1.0.0': { value: 'my-bundle-package@1.0.0/lib/index', exactMatch: true}
'isobject@2.1.0': { value: 'isobject@2.1.0/index', exactMatch: true},
'isarray@2.0.0': { value: 'isarray@2.0.0/index', exactMatch: true},
'isarray@1.0.0': { value: 'isarray@1.0.0/index', exactMatch: true},
...
}
注:
Liferay.PATHSプロパティは、JavaScriptモジュールファイルへのパスを記述します。Liferay.MODULESプロパティは、各モジュールの依存関係の名前とバージョンを記述します。Liferay.MAPSプロパティは、パッケージのメインモジュールのエイリアスを示します。