adobe / adobe/htlengine

feature request: allow resource precompiling

Open
#198 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
49
Forks
20
Avg merge
3h 46m
Merged PRs (30d)
1

Description

the `@adobe/htlengine` supports two ways to include content into a template:

**`data-sly-call`**

The directive `data-sly-use` is executed during compile time and uses the `@adobe/htlengine` templateLoader to include the html file.
During runtime it executes the template:

```html

```

**`data-sly-resource`**

The directive `data-sly-resource` is executed only during runtime and therefore we are not able precompile the template in `project/components/content/articleTeaser/teaserItem` although it is already known.

```html

```

will be compiled to: `const var_resourceContent1 = yield $.slyResource("teaserItem", {"resourceType": "project/components/content/articleTeaser/teaserItem", });`

Would it be possible to add a feature similar to the `defaultModuleGenerator` which allows custom precompiling for `data-sly-use` also for `data-sly-resource`?

The main motivation behind this feature request is the goal to run `data-sly-resource` inside a browser without the need of a running server to render the resource template.

Right now the compiler accepts a moduleMap with the argument called `mods`:

```js
const parseResult = await this._parse(source, baseDir, mods);
```

One idea how we might achieve add is new feature would be to rename `mods` to `meta` and allow a substructure like this

```
meta = {
mods: { /* all previous module mappings */ },
resources: { /* resource values */ },
}
```

That way we could add a preprocessor api for the resources and allow modifications during compile time:

```js
compiler
.withResourceLoader(function(resource) {
console.log(resource); // -> {"resourceType": "project/components/content/articleTeaser/teaserItem"}
return JSON.stringify(resource);
})
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.