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

preloaded files are not rendered with renderBuiltUrl #9680

Closed
7 tasks done
danielroe opened this issue Aug 15, 2022 · 1 comment · Fixed by #9938
Closed
7 tasks done

preloaded files are not rendered with renderBuiltUrl #9680

danielroe opened this issue Aug 15, 2022 · 1 comment · Fixed by #9938

Comments

@danielroe
Copy link
Contributor

danielroe commented Aug 15, 2022

Describe the bug

I would expect that the preload links would also be processed with renderBuiltUrl. Instead, even if I wish to render a relative url, I have to set base: './' rather than { relative: true }.

const relativePreloadUrls = config.base === './' || config.base === ''
const scriptRel = config.build.polyfillModulePreload
? `'modulepreload'`
: `(${detectScriptRel.toString()})()`
const assetsURL = relativePreloadUrls
? `function(dep,importerUrl) { return new URL(dep, importerUrl).href }`
: `function(dep) { return ${JSON.stringify(config.base)}+dep }`
const preloadCode = `const scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};export const ${preloadMethod} = ${preload.toString()}`

Not entirely sure how to resolve. Possibly a new hostType, like preload, in which case filename would be the variable name itself (dep) rather than a string?

Reproduction

https://stackblitz.com/edit/vitejs-vite-n3egg4

  1. npm run build
  2. Look in dist/assets/index.1ebc8c94.js
const _sfc_main = {
  __name: "App",
  setup(__props) {
    const HelloWorld = defineAsyncComponent(
      () => __vitePreload(() => import("./HelloWorld.ce23a96f.js"), true ? ["assets/HelloWorld.ce23a96f.js","assets/HelloWorld.2fcbde52.css"] : void 0)
    );
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(HelloWorld), { msg: "Vite + Vue" });
    };
  }
};

System Info

Stackblitz

Used Package Manager

npm

Logs

No response

Validations

@patak-dev
Copy link
Member

Thanks for creating the issue @danielroe, at the end we didn't create one to track this missing feature.

Not entirely sure how to resolve. Possibly a new hostType, like preload, in which case filename would be the variable name itself (dep) rather than a string?

What we discussed in the context of:

build: {
	preload: boolean | { 
      processUrl: (url: string) => boolean | string | (variableName: string) => string,  
    }
}

The idea was that the context was different enough that was better to avoid overloading renderBuiltUrl. The only issue I see is that if we graduate renderBuiltUrl to a hook, then plugins are going to be able to collaborate constructing it, but they would not be able to do the same with preload URLs. Maybe instead of adding it to build.preload we could have an experimental.renderPreloadUrl and leave build.preload only for global disable/filtering. renderPreloadUrl can have most of the same params as renderBuiltUrl (except for hostType that is always JS, and filename is varName`).

I'll see if I can work on this feature later this week.

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

Successfully merging a pull request may close this issue.

2 participants