plone / volto

React-based frontend for the Plone Content Management System
https://demo.plone.org/
MIT License
448 stars 610 forks source link

[Addons] Extend configuration object from addons #1531

Closed sneridagh closed 3 years ago

sneridagh commented 4 years ago

@tiberiuichim proposal: https://gist.github.com/tiberiuichim/eb20c6c18210c384e57028f94d9f4b18

EEA apply Volto addons config:

1396

sneridagh commented 4 years ago

meta issue: #1433

tiberiuichim commented 4 years ago

Based on discussions with @sneridagh

Each Volto project will expose a key like this in its package.json:

"addons": [
"volto-addon-a",
"volto-addon-b:loadExtra,loadSomethingElse"
]

Then we will have a helper function that can be used in the config.js of each project:

import { loadAddons } from '@plone/volto/helpers';

const config = applyAddonsConfiguration(voltoConfig);

We need to implement the loadAddons method. It should require('~/../package.json') and read the addons key.

Naming an addon simply, like "volto-addon-a" in the addons list will load as a configuration function its default export. The configuration function signature is config => config, it's a function that takes a config object as argument, changes it and returns it.

Adding additional names to the addon name will look for optional exports from the addon and load them, the same as above. This makes it possible to include optional configuration from an addon.

tiberiuichim commented 4 years ago

Another discussion with Victor:

The rule is: addon packages can customize Volto, but they can't customize other addon packages We (in the frontend package) can customize other addons.

First we allow addons to customize Volto, then we come in and override any such customization, then customize the addons themselves.

If any addon wants to customize Volto, it needs to write a voltoCustomizationPath key in package.json, with the path to the package-relative customization folder. The customizations inside an addon sit in the addon src folder.

The frontend package can customize addons by having a folder with the addon name in the "addonsCustomizationPath" folder, for example, to customize volto-addons/actions.js, create a file and folder in src/customizations/volto-addons/actions.js

sneridagh commented 4 years ago

@robgietema we also briefly need to discuss this

tiberiuichim commented 4 years ago

We don't want to specify customization paths in package.json in project and addons. There will be a convention that the customization path is always "customizations", inside the project and each of the addon.

If the project has a "volto" folder inside the customizations folder, we go for "new style", with addon customizations by name in the customization folder. If it doesn't have a volto folder inside, we go for old style.

tiberiuichim commented 4 years ago

@iFlameing we have code here that might help you: https://github.com/eea/volto-base/blob/master/src/razzle.config.js

iFlameing commented 4 years ago

@tiberiuichim thank you :)

sneridagh commented 4 years ago

@iFlameing I think since @tiberiuichim and Co. has already worked out the solution and we have discussed it thoroughly we should leave the issue to them, unless you already have advance a lot on it.

iFlameing commented 4 years ago

@sneridagh ok!! I haven't done so much.