Skip to content
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

Add a plugin hook like 'insertTagsToHtml' to support dynamic public path in the index.html #18100

Open
4 tasks done
Mumujianguang opened this issue Sep 13, 2024 · 0 comments
Open
4 tasks done

Comments

@Mumujianguang
Copy link

Description

there have a demand that I need to implement dynamic public path in index.html, I want to change all the link/script tags to dynamic tag, because the public path of our resource is configurable, this means that it may be changed in production environment

I found a plugin hook named transformIndexHtml, but all the tags had already been inserted when it was invoked, although I could still implement my demand through a series of logic, but I feel it's not elegant, like patching

Suggested solution

Add a plugin hook like insertTagsToHtml

function vitePlugin() {
    return {
        name: 'demo',
        insertTagsToHtml(html, assetTags) {
            // TODO
            return html
        }
    }
}

developer can get the assetTags before inserting it into html and finally using returned html as result

image

Alternative

No response

Additional context

No response

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants