-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
__vitePreload dependencies could be relative to import.meta.url #2009
Comments
It does take the base option into account - or do you intend to deploy it at unknown base locations? |
Oh it looks like you are using Vite to build a lib with custom output filenames... yeah the current preload does assume an app with a known base location and can be improved. |
Actually, in my case Rejecting the promise if the link errors might be worth doing independently of that anyway — would a PR be useful? |
Came across that situation yesterday! (wanted the app to work from Setting ¹ unless you depend on the dynamic import polyfill because this upstream PR to resolve from |
Absolutely! |
I have the same issue. We build locally where it will find the files using relative path, but in production the files are located on a cdn while website on a different webserver, so we're getting a bunch of 404's in the network traffic, before the same files are loaded using the base url. So the current behavior still loads the files, but the expected behavior would be to point the preload to the cdn, respecting the base url. |
Another use case that this breaks is when trying to launch a sveltekit app from a chrome extension. This is a big deal in a content script, especially, where it's trying to preload those links via the embedded page's url. I'm actually skipping the generated page to run the start script directly, but the module preload still throws a bunch of errors, and all of the css fails to load. I'm still working out exactly what needs to happen and if there's a workaround, but this is pretty much putting the kibosh on my dreams of running sveltekit from an extension. |
I found a workaround presuming I have a stable chrome extension ID: I can provide vite/packages/vite/src/node/utils.ts Lines 103 to 104 in 82dc588
where chrome-extension is not a valid external URL. Would appreciate a fix for that aspect, at least. |
配置选项build.lib中 __vitePreload让我很头疼,现在不知道该怎么处理 |
Hi there! I Thank you for this amazing project. After a lot of fiddling around with the .
├── index.php
└── subfolder
├── assets # my equivalent of 'dist' folder
├── assets-src # my equivalent of default 'src' folder
├── composer.json
├── composer.lock
├── lib
├── node_modules
├── package-lock.json
├── package.json
└── vite.config.js My import { resolve } from 'path';
import { defineConfig } from 'vite'
import liveReload from 'vite-plugin-live-reload'
export default defineConfig(({ command, mode }) => {
return {
base: './', // resolves correctly for css assets when being built. doesn't resolve in either scenarios for js import statements
build: {
target: 'es2015',
outDir: 'assets',
rollupOptions: {
input: {
frontend: 'assets-src/frontend.js',
admin: 'assets-src/admin.js'
},
output: {
entryFileNames: `[name].js`,
chunkFileNames: `[name].js`,
assetFileNames: `[name].[ext]`
}
},
},
server: {
host: 'vite-with-backend.test',
port: 3000,
strictPort: true
},
}) I was able to solve this by using an absolute path as const basePath = __dirname.split('/wwwroot')[1]; // wwwroot is the very root folder
base: command === 'serve' ? basePath : `${basePath}/assets/`, ...but I often have the scenario that my local development path is different to the path in production (e.g. when I install a website on the remote server inside a sub-directory, but my local site is running in the root). My suggested solution would be to detect if let base = "./";
if( base === "./" ) base = new URL(import.meta.url).pathname.replace(/\/[^\/]+$/, '/'); |
Had the same problem as @olemarius. Solved it with https://github.com/jy0529/vite-plugin-dynamic-publicpath |
You can set the base path now, but it's turned out not to be sufficient for the SvelteKit use case. It's still be nice to remove that and make it relative. E.g. for deploying to IPFS and other targets as described in sveltejs/kit#595 |
@eigan Thank you. Ive been looking for this plugin for quite some time. |
Describe the bug
__vitePreload
includes assumptions about where assets are being served from. In a normal Vite project those assumptions hold true, but in more bespoke situations they may not.Additionally, in the case where CSS dependencies fail to load (whether due to a network failure, or because of the situation described above) the promise returned from
__vitePreload
will never resolve.Reproduction
https://github.com/Rich-Harris/vite-preload-repro
Given sources like this...
...and a config like this...
...the resulting dist/index-ed8ec7ff.js file contains this line:
In the case where assets are served from somewhere other than
/
(for example, on an external CDN), the/foo-5368ca0f.js
and/foo-0a0d0fb0.css
paths are meaningless. If they were relative paths instead, the implementation of__vitePreload
could add the following...return Promise.all(deps.map((dep) => { + dep = new URL(dep, import.meta.url).href; if (dep in seen) return;
...and the resulting files would be more portable.
Meanwhile, to prevent the promise from hanging:
System Info
vite
version: 2.0.0-beta.69The text was updated successfully, but these errors were encountered: