Search code examples
plonegenericsetupplone-5.x

How to migrate resources registry resources to Plone 5


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.


Solution

  • 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: