4

I have an add-on (collective.lazysizes) that includes a couple of JavaScript resources into Plone 4 resource registry using the following jsregistry.xml file:

<?xml version="1.0"?>
<object name="portal_javascripts">
  <javascript id="++resource++collective.lazysizes/ls.respimg.min.js"
      cacheable="True" compression="none" cookable="True" enabled="True"
      expression="" inline="False" />
  <javascript id="++resource++collective.lazysizes/lazysizes.min.js"
      cacheable="True" compression="none" cookable="True" enabled="True"
      expression="" inline="False" />
</object>

How do I convert this into a Plone 5 bundle in registry.xml? Do I have to join the scripts into one file? How? Do I have to add a resources key into the bundle? What should it contain? What about more than one CSS resources?

I found the documentation complex, sometimes contradictory and not pretty clear on this.

hvelarde
  • 2,875
  • 14
  • 34
  • I note that [lazysizes.(min.)js](https://github.com/aFarkas/lazysizes/blob/gh-pages/lazysizes.js#L6) is already compatible with requirejs (if I read it correctly). I'm not sure about the plugin though.... – Danimal Feb 24 '16 at 13:38

1 Answers1

3

Here is what I would do:

  • put all your JS in a single file (named lazysizes-bundle.js for instance). It can be done manually by copy/pasting them (we might also use npm and gulp, declare our JS dependencies in package.json and generate this bundle automatically, but in this very case, that's just 2 files, it might be overkill),

  • declare this bundle in registry.xml:

<records prefix="plone.bundles/lazysizes" interface='Products.CMFPlone.interfaces.IBundleRegistry'> <value key="enabled">True</value> <value key="jscompilation">++resource++collective.lazysizes/lazysizes-bundle.js</value> <value key="last_compilation">2016-01-01 00:00:00</value> <value key="compile">False</value> <value key="depends">plone</value> </records>

We set compile to False so Plone will not try to generate this bundle, so our manually-generated bundle is preserved.

Notes:

ebrehault
  • 2,471
  • 21
  • 22
  • 1
    shouldn't it be added to the Plone bundle, rather than creating a new bundle? – Danimal Feb 24 '16 at 13:00
  • Nice point @Danimal. Defining a new bundle for every add-on will lead Plone to have *a lot* of bundles? – keul Feb 24 '16 at 13:20
  • @ebrehault the part of the documentation that confuses me more is the one stating [Plone will add all jsregistry.xml JavaScripts and cssregistry.xml CSS into a "plone-legacy" Resource Registry bundle](http://docs.plone.org/adapt-and-extend/theming/resourceregistry.html#old-registry-migration-and-compatibility); this should work, but is not. – hvelarde Feb 24 '16 at 13:45
  • @Danimal Plone default bundles are generated using a frontend tool chain (in the mockup package) and it is not easy (nor desirable) to integrate add-ons JS/CSS into those bundles. – ebrehault Feb 24 '16 at 16:15
  • 1
    @keul yes each add-on will bring its own bundle, BUT they can be merged into metabundles (see https://github.com/plone/Products.CMFPlone/issues/1277 that will be part of 5.0.3). – ebrehault Feb 24 '16 at 16:16
  • @ebrehault that's an important news! Please consider adding this also to you answer! – keul Feb 24 '16 at 17:33