bennypowers / rollup-plugin-modulepreload

Rollup plugin to add modulepreload links from generated chunks.
MIT License
16 stars 0 forks source link

Expose the modulepreload entry graphs rather than modifying HTML #4

Open philipwalton opened 5 years ago

philipwalton commented 5 years ago

For my modulepreload use case, I don't have a static HTML file that I want to modify, I have a template file that I want to pass data to (e.g. the list of files that need preloading). It looks something like this:

{% for module in modulepreload %}
    <link rel="modulepreload" href="/public/{{ module }}"></script>
{%- endfor %}

At the most basic level, what I need from a modulepreload plugin for Rollup is something that inspects my bundle and gives me back a list files that need preloading. Then I (myself) can chose what I want to do with that list of files, and how I want to get it into my HTML.

There are also cases where the list of files to preload depends on what URL the user navigates to, and that can only be determined at run time, not at build time. In such cases a template would need more than just a single list, it would need a mapping of entry points to their static graphs (I've filed #3 to address that issue).

This issue is more about answering the question of how a developer gets the list of files to preload from this plugin to the HTML. I think letting them pass a function to the plugin that gets invoked with the entry graphs should be sufficient.

bennypowers commented 5 years ago

This sounds like a very useful feature I'd be happy to review a PR