-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Opt-out of asset inlining - with SSR support #15986
Comments
Vite 5.1+ supports callback style assetsInlineLimit: (file) => {
return !file.endsWith('.svg');
} |
@sapphi-red Thank you. Forgot to mention it in the issue body. However, I am not sure if it is a friendly DX - especially for specific files. const configuration = {
build: {
assetsInlineLimit: (file) => {
const pathnames = [`${process.cwd()}/src/lib/static/background.svg`];
if (pathnames.includes(file)) return false;
},
},
};
// vs
import background from '$lib/static/background.svg?url'; |
Related: #15454 |
The downside of using a query is the possibility of bundling a single file both as inlined and as non-inlined. import backgroundUrl1 from './background.svg?non-inlined-url' // https://...
import backgroundUrl2 from './background.svg' // data:... |
Closing as #15454 is merged. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Allow individual static asset imports to opt-out from inlining.
The following SVG file is inlined in the build process.
Currently, asset inline can only be disabled globally.
Suggested solution
Utilize the explicit URL import syntax.
Alternative
The
new URL(url, import.meta.url)
method exists, but it does not work in SSR.https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url
Additional context
Related issue and PR:
SvelteKit context:
/static
directory.https://github.com/sveltejs/kit/blob/511126b51d4aaa770704491ff0890a76fa116205/packages/adapter-node/src/handler.js#L54-L56
Validations
The text was updated successfully, but these errors were encountered: