Using the NPMResolver API in Your Portlets

If you’re developing an npm-based portlet, your OSGi bundle’s package.json is a treasure-trove of information. It contains everything that’s stored in the npm registry about your bundle: default entry point, dependencies, modules, package names, versions, and more. The NPMResolver APIs expose this information so you can access it in your portlet. If it’s defined in the OSGi bundle’s package.json, you can retrieve the information in your portlet with the NPMResolver API. For instance, you can use this API to reference an npm package’s static resources (such as CSS files) and even to make your code more maintainable.

To enable the NPMResolver in your portlet, use the @Reference annotation to inject the NPMResolver OSGi component into your portlet’s Component class, as shown below:

import com.liferay.frontend.js.loader.modules.extender.npm.NPMResolver;

public class MyPortlet extends MVCPortlet {
  private NPMResolver `_npmResolver`;

Now that the NPMResolver is added to your portlet, read the topics in this section to learn how to retrieve your OSGi bundle’s npm package and module information.

« Creating Custom Loaders for the liferay-npm-bundlerReferencing an npm Module's Package to Improve Code Maintenance »
Was this article helpful?
0 out of 0 found this helpful