We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.
<style> .img { width: 200px; height: 200px; background: url("@/assets/logo.png") center / contain no-repeat; } </style>
The alias (@) is not resolved to its correct path defined in vite.config.js:
@
vite.config.js
import path from "path"; import vue from "@vitejs/plugin-vue"; /** * @type {import('vite').UserConfig} */ export default { resolve: { alias: { "@": path.join(__dirname, "src"), }, }, plugins: [vue()], };
I tried to fix it in assets.ts with the following:
- const file = url.startsWith('/') - ? path.join(config.root, url) - : path.join(path.dirname(importer), url) + let file + if (url.startsWith('/')) { + file = path.join(config.root, url) + } else { + const resolved = (await pluginContext.resolve(url, importer))?.id + file = resolved || path.join(path.dirname(importer), url) + }
and in css.ts with the following:
- ? (url, importer) => { + ? async (url, importer) => { if (url.startsWith('/')) { return config.base + url.slice(1) } else { - const filePath = normalizePath( - path.resolve(path.dirname(importer || id), url) - ) + const resolved = (await this.resolve(url, importer || id))?.id + const filePath = + resolved || + normalizePath(path.resolve(path.dirname(importer || id), url)) return fileToDevUrl(filePath, config) } }
https://github.com/sayuti-daniel/vite-css-url-alias
vite
vite build
--debug
The text was updated successfully, but these errors were encountered:
ad50060
No branches or pull requests
Describe the bug
The alias (
@
) is not resolved to its correct path defined invite.config.js
:I tried to fix it in assets.ts with the following:
and in css.ts with the following:
Reproduction
https://github.com/sayuti-daniel/vite-css-url-alias
System Info
vite
version: 2.0.0-beta.70Logs (Optional if provided reproduction)
vite
orvite build
with the--debug
flag.The text was updated successfully, but these errors were encountered: