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

Assets path not replaced by _svelte_kit_assets in preview #12184

Open
drzax opened this issue May 2, 2024 · 1 comment
Open

Assets path not replaced by _svelte_kit_assets in preview #12184

drzax opened this issue May 2, 2024 · 1 comment

Comments

@drzax
Copy link

drzax commented May 2, 2024

Describe the bug

One of the stated use cases for the config.kit.paths.assets config var is for the case where assets will be hosted on a separate domain to the site itself.

The docs state:

If a value for config.kit.paths.assets is specified, it will be replaced with '/_svelte_kit_assets' during vite dev or vite preview, since the assets don't yet live at their eventual URL.

That is what happens with vite dev. When running vite preview however, the value from config is still used. The only relevant previous issue I could find is #1154.

Reproduction

https://github.com/drzax/assets-repro

Logs

No response

System Info

System:
    OS: macOS 14.4.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 839.94 MB / 32.00 GB
    Shell: 5.2.26 - /opt/homebrew/bin/bash
  Binaries:
    Node: 21.7.1 - /opt/homebrew/bin/node
    npm: 10.5.0 - /opt/homebrew/bin/npm
    pnpm: 8.15.7 - /opt/homebrew/bin/pnpm
    bun: 1.0.36 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 124.0.6367.119
    Edge: 124.0.2478.67
    Safari: 17.4.1
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.2.0
    @sveltejs/adapter-static: ^3.0.1 => 3.0.1
    @sveltejs/kit: ^2.0.0 => 2.5.7
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.0
    svelte: ^4.2.7 => 4.2.15
    vite: ^5.0.3 => 5.2.10

Severity

blocking all usage of SvelteKit

Additional Information

We need to be able to debug production builds locally and this is currently blocking that.

@Rishab49
Copy link

I think there is an error in documentation because during the build time the path of stylesheets are created and if we have an path.assets available then it will be added in the path of the stylesheets

here since the path of stylesheet is something like app/immutable/assets/something.css, so if condition will not get executed and our path will get prefixed with path.assets(line 212)

const prefixed = (path) => {
if (path.startsWith('/')) {
// Vite makes the start script available through the base path and without it.
// We load it via the base path in order to support remote IDE environments which proxy
// all URLs under the base path during development.
return paths.base + path;
}
return `${assets}/${path}`;
};

and it will get statically added in the html markup

for (const dep of stylesheets) {
const path = prefixed(dep);
const attributes = ['rel="stylesheet"'];
if (inline_styles.has(dep)) {
// don't load stylesheets that are already inlined
// include them in disabled state so that Vite can detect them and doesn't try to add them
attributes.push('disabled', 'media="(max-width: 0)"');
} else {
if (resolve_opts.preload({ type: 'css', path })) {
const preload_atts = ['rel="preload"', 'as="style"'];
link_header_preloads.add(`<${encodeURI(path)}>; ${preload_atts.join(';')}; nopush`);
}
}
head += `\n\t\t<link href="${path}" ${attributes.join(' ')}>`;
}

so IMO an easy solution will to just comment out the assets path line during local build.

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