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

Load all files from the entry location #7930

Closed
4 tasks done
leifmarcus opened this issue Apr 27, 2022 · 3 comments
Closed
4 tasks done

Load all files from the entry location #7930

leifmarcus opened this issue Apr 27, 2022 · 3 comments

Comments

@leifmarcus
Copy link

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 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 time
if (public === 'auto') {
  const { src } = document.currentScript;
  public = src.substr(0, src.indexOf(base))
}

// inside the preload function:
dep = `${public}${base}${dep}`

For 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

@patak-dev
Copy link
Member

Would you check if this PR covers your needs?

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)

@leifmarcus
Copy link
Author

Thank you @patak-dev. If ./ or auto works as described in the linked issue, I’m totally fine and you might close my request. Thanks for reaching out!

@patak-dev
Copy link
Member

Ok, closing as duplicate of #2009. I'll try to push #7644 for Vite v3 (the next release)

@github-actions github-actions bot locked and limited conversation to collaborators May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants