Another report from PLOG, sorry for the delay
Attendees
- Jens Klein
- Víctor Fernandez
- Gil Forcada
- Johannes Raggam
We (i.e. the attendees listed above) discussed the current status of the JavaScript in Plone and a possible way forward.
DISCLAIMER
is the header big enough? That was just a proposal, there is still no PLIP for it, although the idea is to create one if the feedback is positive. So, please, we warmly welcome constructive feedback.
PROPOSAL
First we set some goals and we tried to identify the use cases:
Goals
- Define a way to make JavaScript integration in Plone sane and great again (same with CSS)
- Use modern JavaScript tooling and widely accepted way of bundling
- Decouple Plone Python code and Plone JavaScript/CSS code
- from Python POV be agnostic which tools are used for JS/CSS
Use cases
- Plone core itself
- add-ons that want to provide extra JS/CSS on top of Plone
- themers that want to provide extra or completely replace Plone JS/CSS
Prerequisites
The default install experience, should not change at all: you create a Plone instance and JS and CSS will be provided by the default theme (barceloneta in Plone 5.x) without having to have any knowledge on JS tooling.
So in short: the usual workflow to develop Plone (not JS/CSS for Plone) should not need any change.
TL;DR
- all JS/CSS released as npm modules
- webpack will be used to assemble all JS/CSS and released as an NPM module as well to be used by for Plone core and extended by themers
- integrators are encouraged to use the same approach
- add-ons are encouraged to dually release on NPM and PYPI but a fallback (a simple resource registry) will be provided
The story
What will change is that those JS and CSS coming from the default theme will be created and maintained through a Webpack configuration.
For that all Plone related CSS and JS will be released as npm modules as well as the Webpack configuration itself. This way integrators will be able to re-create the default bundles on their own, as well as modifing them as much as they wish with only JS tooling, no Plone/Python needed at all.
In this scenario, the only Python egg package released on pypi that should contain JS and CSS will be the default theme, everything else will be in npm modules.
Add-on developers, just like core Plone, will be encouraged to dually release their add-ons: the Python part as an egg at PyPI, the JS/CSS at npm.
To install them one will have to add a line in buildout (for the python egg) and a line on the webpack configuration (for the npm module).
Run buildout/webpack and update their servers with them.
As a fallback for small/tiny JS/CSS fixes a simple resource registry will still exist but will not do any dependency management/concatenation/minification/etc it will deliver all JS/CSS registered there one after the other. So, it will be the responsibility of the add-on developer to ensure that these JS/CSS have all their dependencies resolved, etc.
With this fallback resource registry, add-ons that are still not ported might work if their JS provides all the dependencies or are lucky enough that the dependencies are already loaded by the time they run (they will be appended at the end of the scripts tags).
This resource registry will be prominently advertised as a fallback practice and documentation on how to use the best practice (i.e. release it as npm modules) will be created.
This way, hopefully, add-on developers are not left in the cold on how to port their add-ons while at the same time their are allowed to have a minimal integration in Plone without having to go through the JS/CSS route (i.e. avoiding webpack all together if they wish).
If an add-on is released as an npm module, one can integrate it in their own theme's webpack configuration. That will disable the bundle provided by the Python egg itself (if it is using the fallback resource registry at all). This ensures bundles are not loaded twice. Each add-on must provide a unique ID (namespace) for each bundle it provides (anonymous, logged-in, ...). The npm module should provide those IDs as metadata in order to let webpack read that data and add it to the theme MANIFEST.in. Plone will read the MANIFEST.in and disable those bundles.
The TTW theme editor will still allow to add plain CSS/LESS/SASS that will get compiled and added as the last extra CSS file being loaded.
TTW no JavaScript will be compiled nor we will encourage TTW developers to add JavaScript. The only JavaScript added is - as it is in 5.1 and earlier already - those for Analytics configured in Control Panel. However, if a developer knows what she/he is doing Diazo may be used to add a custom JavaScript file at the end of the chain. This will not be officially supported nor encouraged.
Why webpack
- maturity: a major refactoring of it already happened (v2), so it should be fairly stable and it has been around for quite a while (2012, which by JS standards that's A LOT)
- it supports all kinds of JS: AMD, commonJS, ES6, babel (to transpile...)
- there is integrations with Plone already: see Asko's and Eric Brehault's work
- small overhead: together with ES6 (preferably), npm scripts and webpack itself is the minimal needed to start hacking on JS, so the amount of tools/technologies to learn is really small
- it is backed by a huge open source community: more active developers than Plone itself
Migration
- make the current (5.1) resource registry output a webpack configuration that can be used standalone
Roadmap/TODO
- it will be nice to secure the @collective namespace in npmjs
- zest.releaser could be improved to deal with npm packages as well to automate things (there is https://pypi.python.org/pypi/yarn.build that could be used as a base)
- put all JS/CSS from Plone in npm packages
- create a webpack configuration (based on Asko's work) and publish that as well as an npm module
- write guidelines to port existing JS/CSS to the new approach
- improve https://github.com/datakurre/plonetheme.webpacktemplate and host it on plone org itself (?)
- (?) migration script to export current (Plone 5.1) JS/CSS to the filesystem so that webpack can process it
Final notes
On PLOG there were no major concerns (anyway we were only discussing rather than implementing) and the sprint in Finland later on this year can be a good opportunity to start working on it, specially given that the main idea is to make @datakurre's webpack plugin saner by avoiding lots of the black magic is currently doing to achieve more or less what we have outlined here.