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

proposal: index.html substitution #1

Closed
Menci opened this issue Feb 14, 2022 · 4 comments
Closed

proposal: index.html substitution #1

Menci opened this issue Feb 14, 2022 · 4 comments

Comments

@Menci
Copy link

Menci commented Feb 14, 2022

This plugin just handles JS files but the index.html still just loads the module files from the origin host. We need to patch index.html to let redirect the initial module load to the CDN host.

I created another plugin to do this in my project, which transforms <link> and <script> tags to JS calls of a given function (which should be declared in index.html file, together with placeholders to inject the JS code to).

See the usage of my current implementation: plugin configuration and index.html (for <link> and <script>).

I could create a PR If you consider this feature useful.

@Menci
Copy link
Author

Menci commented Feb 14, 2022

Note: since the bug vitejs/vite#5851, index.html substitution will only work with legacy builds after vitejs/vite#6901 landed.

@chenxch
Copy link
Owner

chenxch commented Feb 15, 2022

This is also a question I have been thinking about recently. The function has actually been implemented, but I feel that there are still shortcomings. It is always necessary for the user to assign a value to the publicPath before the loader is executed. I will submit the code later. Late tomorrow morning.
I have read your solution in detail, it is a good solution, but I prefer to integrate the loader to reduce the cost of use.
Finally, thank you very much for your valuable suggestions and solutions.

@Menci
Copy link
Author

Menci commented Feb 15, 2022

Integrating the loader sounds much more convenience but lose customization. For example if I load HTML and JS from different origins there's likely a chance that the HTML file is loaded but the JS is failed. If use a own loader the developer could attach a onerror event to the injected tag. But it's fine since there will be other methods to handle this.

I'll continue to follow up your implementation after vitejs/vite#6901 landed.

@chenxch
Copy link
Owner

chenxch commented Feb 16, 2022

One scenario I can think of is the external dependencies in webpack, like the vue family bucket is loaded through the a.cdn.com path, and the project itself is loaded through the b.cdn.com path. At present, this plug-in is relatively simple to design for a whole project, of course, I also hope to improve this plug-in with your help.

@chenxch chenxch closed this as completed Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants