ampproject / ampproject/amp-toolbox
[optimizer] Enable adding custom transformation to the config
- Dominant language
- HTML
- Stars
- 459
- Forks
- 242
- PR merge metrics
- No merged PRs in 30d
Description
The default config for the optimizer is not exposed. When a developer needs to add a custom config it is necessary to re-add the whole configuration, like in the example below:
```javascript
ampOptimizer.setConfig({
transformers: [
new CustomTransformer(),
'AddAmpLink',
'ServerSideRendering',
'RemoveAmpAttribute',
// needs to run after ServerSideRendering
'AmpBoilerplateTransformer',
// needs to run after ServerSideRendering
'ReorderHeadTransformer',
// needs to run after ReorderHeadTransformer
'RewriteAmpUrls'
]
});
```
The new API should enable developers to add new Transformers. A proposal would be:
```javascript
const config = new ConfigBuilder()
.default() // Adds the default configuration
.addPreloadImages() // Easy to enable non-default transformers
.addTransformer(new CustomTransformer()) // Enables adding user authored transformers.
.build();
ampOptimizer.setConfig(config);
```
Contributor guide
Research direction
No files, tests, or entry points are named. Start by locating the optimizer's configuration and default transformer setup, then determine how a ConfigBuilder could expose the defaults and custom transformer additions; done means developers can extend the default configuration without re-adding every transformer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100