You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a developer using Vite I want to request all assets/css/js from the entry location so that I'm able to provide a single build from different locations.
Suggested solution
As far as I understand, currently the __vitePreload method handles the dependency preloading, but also the loading of the dependencies.
So my suggestion would be to add a config property like public next to the base property. This can be set to an absolute url like 'https://my-cdn.something.com' or to 'auto'.
At the moment, you define the path inside the preload function like
dep=`${base}${dep}`;
The implementation of the automatic approach using document.currentScript.src could look like
// get values from the vite config:const{ base, public =''}=viteConfig;// define the public path automatically// I guess it should not be part of the preload function to not be called every timeif(public==='auto'){const{ src }=document.currentScript;public=src.substr(0,src.indexOf(base))}// inside the preload function:dep=`${public}${base}${dep}`
The context in my case is, that we have multiple environments to test the application that request the files from different endpoints but use the same build. In prod we use a cdn, but on testing environments we have a local folder on the web server.
You would need to set base: './'. We're discussing if adding a new base: 'auto' would make things more clear. There is also a discussion here that may interest you #3522 (comment)
Clear and concise description of the problem
As a developer using Vite I want to request all assets/css/js from the entry location so that I'm able to provide a single build from different locations.
Suggested solution
As far as I understand, currently the
__vitePreload
method handles the dependency preloading, but also the loading of the dependencies.So my suggestion would be to add a config property like
public
next to thebase
property. This can be set to an absolute url like'https://my-cdn.something.com'
or to'auto'
.At the moment, you define the path inside the preload function like
The implementation of the automatic approach using
document.currentScript.src
could look likeFor legacy IE browsers a polyfill needs to be used for the currentScript implementation like https://github.com/amiller-gh/currentScript-polyfill.
Alternative
So fare I don’t have any alternative approach.
Additional context
The context in my case is, that we have multiple environments to test the application that request the files from different endpoints but use the same build. In prod we use a cdn, but on testing environments we have a local folder on the web server.
Validations
The text was updated successfully, but these errors were encountered: