Uploaded image for project: 'Magnolia CLI'
  1. Magnolia CLI
  2. NPMCLI-38

Use resources from other npm packages in one module

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Neutral Neutral
    • None
    • None
    • None
    • Basel 83
    • 1

      It should be easy to setup a single light module so that it uses web resources from other npm packages.

      For example if I want to create a light module which provides a component which provides a carousel based on "slick-carousel" (https://www.npmjs.com/package/slick-carousel), my new component should not need to copy and include the web resources of this other module - it should be able to simply depend on this other package, and somehow specify which of its resources it needs.

      Reasoning:
      A key benefit and principle of npm, is that a package can depend on others so that it does not duplicate what is already available elsewhere. If we do not adhere to this principle, developers will be confused and dissapointed.

      Example of a light module that could use this: https://www.npmjs.com/package/responsive-image-component
      It includes the lazySizes.js file - but it should not. It should simply depend on the lazy-sizes npm package.
      (https://www.npmjs.com/package/lazysizes)

      Background:
      Previously this was solved with the lightDevCopyResources configuration - but that has issues now that mgnl is installed globally. See linked ticket.

      Note:
      resfn (available since Magnoila 5.5.1) makes it easy for a template to include resources in the light modules. It may be part of the solution here, but by itself it does not address the issue of resources from other npm packages.

      Conclusion:
      Use standard frontend build tool such as webpack to bundle dependent resources and place them in webresources.
      This is done with pre-publish hook so that the npm package has all resources necessary - ready to go.
      We provide advice on which common large libraries should rather not be automatically bundled in the interest of saving space (but the downside of additional complexity for consumer of package.) (We are not talking about the project here.)
      If that is too complicated, users can grab the dependency manually.

        Acceptance criteria

              rkowalski Robert Kowalski
              czimmermann Christopher Zimmermann
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Task DoD