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

URL of public assets is wrong in built CSS files if assetsDir is set and base is './' #3650

Closed
6 tasks done
Undefined100 opened this issue Jun 2, 2021 · 4 comments · May be fixed by StemmlerSisters/vite#2
Closed
6 tasks done
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@Undefined100
Copy link

Undefined100 commented Jun 2, 2021

Describe the bug

当我将静态资源(图片,字体)放在public文件下时,打包之后,css文件中静态资源引用路径不对

Reproduction

Github Repo Link

System Info

System:
OS: macOS Mojave 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
Memory: 986.89 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 14.16.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.11 - /usr/local/bin/npm
Browsers:
Chrome: 91.0.4472.77
Safari: 14.1
npmPackages:
vite: ^2.3.5 => 2.3.5

Used package manager:

Logs


Before submitting the issue, please make sure you do the following

@javastation
Copy link
Contributor

public 里的资源要以/开头,所以你应该 background-image: url('/static/img/logo.png'); base最好设置成绝对路径或者 URL,设置为"",在 dev 时会被替换为/,build 时则保持不变,base设置""可以看issues 1669

@Undefined100
Copy link
Author

Undefined100 commented Jun 3, 2021

public 里的资源要以/开头,所以你应该 background-image: url('/static/img/logo.png'); base最好设置成绝对路径或者 URL,设置为"",在 dev 时会被替换为/,build 时则保持不变,base设置""可以看issues 1669

将base设置成'./'后,构建出来的css文件中的路径还是错误的,我代码已经上传了Github Repo Link,vue-cli中生成的路径都是正常的

@haoqunjiang
Copy link
Member

haoqunjiang commented Jun 3, 2021

你这个用法有点太特殊了……
所以这个问题只会出现在 base: './' 并且用了 assetsDir 的情况下……

@haoqunjiang haoqunjiang reopened this Jun 3, 2021
@haoqunjiang haoqunjiang changed the title 打包后,css文件中静态资源引用不对 Wrong url in built CSS files if `base: Jun 3, 2021
@haoqunjiang haoqunjiang changed the title Wrong url in built CSS files if `base: Wrong url in built CSS files if assetsDir is set and base is './' Jun 3, 2021
@haoqunjiang haoqunjiang changed the title Wrong url in built CSS files if assetsDir is set and base is './' Wrong URL in built CSS files if assetsDir is set and base is './' Jun 3, 2021
@haoqunjiang haoqunjiang added bug feat: css p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Jun 3, 2021
@haoqunjiang haoqunjiang changed the title Wrong URL in built CSS files if assetsDir is set and base is './' URL of public assets is wrong in built CSS files if assetsDir is set and base is './' Jun 3, 2021
@sapphi-red
Copy link
Member

After upgrading to 3.0.0-alpha.1, it worked. I assume #7644 has fixed this.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
4 participants