-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate HTML Snippets for Backend Integration #19578
Comments
In my current team, we found the need for this functionality. Initially, I considered implementing it as a Vite plugin, but after exploring the Plugin API, I realized that the available information was insufficient for generating the necessary HTML snippets. As a workaround, we developed and are currently using a CLI tool that loads If there are no objections to adding this feature, I would be happy to contribute it myself. |
I guess this can be a plugin by doing this exact transform in I think the things needs to consider are:
By the way, do you have any assets only used from the backend? I guess the current structure of this manifest ( <img src="./path/to/image.png" /> |
Description
Background
Vite provides the
build.manifest
option, which helps integrate with backend frameworks by describing the relationships between built JavaScript and CSS files. Backend frameworks typically parsemanifest.json
and generate<script>
and<link>
tags accordingly, embedding them into their templating systems.https://vite.dev/guide/backend-integration
Example
manifest.json
:Feature Proposal
Instead of requiring backend frameworks to process
manifest.json
and generate HTML tags, Vite could provide an option to generate the necessary<script>
and<link>
tags directly. This would simplify integration with server-side frameworks, reducing the need for custom parsers or code generators on the backend side.According to Conway’s Law, system design tends to mirror organizational structures. By allowing the frontend team to manage asset injection, we can reduce the friction between teams and streamline development.
Motivation
Our team consists of separate backend and frontend teams, working with different programming languages. Currently, backend engineers must understand Vite's manifest format and implement a custom code generator to inject the correct assets. Ideally, Vite-related concerns should be maintained by the frontend team, as this better reflects our team's structure and expertise.
Suggested solution
I propose introducing a new option:
build.generateBackendIntegrationHtml
.When enabled, Vite will generate a file named
.vite/backend-integration-html.json
, which provides pre-generated HTML snippets for embedding assets into backend templates. This eliminates the need for backend frameworks to parsemanifest.json
and construct<script>
and<link>
tags manually.Example
.vite/backend-integration-html.json
:Each entry corresponds to an entry point in the project and contains predefined HTML snippets for different locations within a template (e.g., inside
<head>
or<body>
).The property names (
afterBegin
,beforeEnd
) are inspired byinsertAdjacentHTML
, making it intuitive for developers familiar with DOM manipulation.This structure allows backend frameworks to simply read and insert the required tags without additional processing.
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: