Reblogged from www.nathanvangheem.com
Old style jsregistry.xml
An old style Resource Registry would look like this:
To migrate this to Plone 5, resource registrations are all done in the Configuration Registry.
New style with registry.xml
The new registration will look something like:
<?xml version="1.0"?> <registry> <records prefix="plone.resources/foobar" interface='Products.CMFPlone.interfaces.IResourceRegistry'> <value key="js">.++resource++foobar.js</value> <value key="deps">jquery</value> </records> </registry>
Notice how I've now added the deps property of "jquery". This is not necessary--I'm just giving an example that this script needs a global jquery available.
In this post, we'll describe the process of creating your own bundle. Again, we use registry.xml for configuration:
<records prefix="plone.bundles/foobar" interface='Products.CMFPlone.interfaces.IBundleRegistry'> <value key="resources"> <element>foobar</element> </value> <value key="enabled">True</value> <value key="jscompilation">++resource++foobar-compiled.min.js</value> <value key="last_compilation">2015-02-06 00:00:00</value> </records>
One important aspect here is the "jscompilation" settings. This defines the compiled resource used in production mode.
But, it's a bit more work
That being said, adding resources, bundles and compiling them can all be done Through The Web(TTW) in the new Resource Registries configuration panel. That way you can turn on development mode, compile your resources and then copy that compiled version into your package for distribution and not need to know any newfangled nodejs technologies like grunt, gulp, bower, npm, etc.
Updating non-AMD scripts
Additionally, above this require call, I provide some backward compatible code that you can inspect. It's not necessary in this case but I added it to show how someone could make their script work when requirejs was available and when it was not.
In switching to AMD, the compile step is much more resource intensive. It takes so long, there is no way we could do this real-time. Additionally, it can not be done in Python.
When changes are made to existing bundles, re-compilation will need to be done TTW in the Resource Registries control panel. There is a build button next to each bundle. For advanced users, compilation can be done using a tool like grunt in your development environment.
Topics for another time
You may have noticed that some subjects were glossed over. This post is already long enough but here are some things to not forget about.