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

[v3.x] - public/fonts/font.woff in index.html contains __VITE_PUBLIC_ASSET__ #9174

Closed
7 tasks done
ihmpavel opened this issue Jul 17, 2022 · 4 comments · Fixed by #9247
Closed
7 tasks done

[v3.x] - public/fonts/font.woff in index.html contains __VITE_PUBLIC_ASSET__ #9174

ihmpavel opened this issue Jul 17, 2022 · 4 comments · Fixed by #9247
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@ihmpavel
Copy link

ihmpavel commented Jul 17, 2022

Describe the bug

Working fine prior 3.0.0. Tested up to 3.0.1

Having a font in in /public/fonts/font.woff referencing in index.html makes build not working.

The path is not changed, but contains __VITE_PUBLIC_ASSET__hash__

  1. Create /public/fonts/font.woff (needs to be in fonts folder)
  2. Create index.html with
@font-face {
      font-family: 'Open Sans';
      font-style: normal;
      font-weight: 400;
      font-display: swap;
      src: url('/fonts/opensans-regular.woff2') format('woff2'),
        url('/fonts/opensans-regular.woff') format('woff'),
        url('/fonts/opensans-regular.ttf') format('truetype');
    }
  1. vite build
  2. The created index.html now contains ... src: url('__VITE_PUBLIC_ASSET__f5439943__') format('woff2'), url('__VITE_PUBLIC_ASSET__ee5c699b__') format('woff'), url('__VITE_PUBLIC_ASSET__fbd96617__') .... Public folder has correct files
  3. Load page - fonts will respond 404

Reproduction

https://stackblitz.com/edit/vitejs-vite-5k3e58?file=dist%2Findex.html&terminal=dev

System Info

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 2.79 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
    Yarn: 1.22.19 - ~/.bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Safari: 15.5

Used Package Manager

yarn

Logs

No response

Validations

@ihmpavel ihmpavel changed the title Vite 3.0.0 - public/folder/asset in index.html contains __VITE_PUBLIC_ASSET__ Vite 3.0.0 - public/folder/font.woff in index.html contains __VITE_PUBLIC_ASSET__ Jul 17, 2022
@ihmpavel ihmpavel changed the title Vite 3.0.0 - public/folder/font.woff in index.html contains __VITE_PUBLIC_ASSET__ Vite 3.0.0 - public/fonts/font.woff in index.html contains __VITE_PUBLIC_ASSET__ Jul 17, 2022
@sapphi-red sapphi-red added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jul 17, 2022
@ihmpavel
Copy link
Author

That looks like the issue is with url(...), where vite is trying to do (optimize?) something. Having <link href="/xyz/xyz.png" rel="..." ... /> is working fine.

@ihmpavel ihmpavel changed the title Vite 3.0.0 - public/fonts/font.woff in index.html contains __VITE_PUBLIC_ASSET__ [v3.x] - public/fonts/font.woff in index.html contains __VITE_PUBLIC_ASSET__ Jul 18, 2022
@nvh95
Copy link
Contributor

nvh95 commented Jul 19, 2022

We are having the same issue when migrating vite 2 to vite 3 bestofjs/bestofjs#148 (comment)

It works fine in dev mode.

To reproduce:

git clone https://github.com/bestofjs/bestofjs-webui
cd bestofjs-webui
git checkout 924d740ea6e7f80818d6e183dcef5a4b3e51a316
npm install
npm run build
npm run preview

Open app in browser and navigate to Font requests

image

File such as https://bestofjs-git-vite3-bestofjs.vercel.app/__VITE_PUBLIC_ASSET__03d6a1cf__ does not exist, it supposes to be a woff/woff2 file

Online link:
https://bestofjs-68pbasy3a-bestofjs.vercel.app/

@nvh95
Copy link
Contributor

nvh95 commented Jul 19, 2022

[Update]: Please update to vite >= 3.0.4 to get this issue fixed.
I can find a workaround by changing the URL of the font to the relative path. You can use this while Vite team is working on this.

-        src: url('/fonts/OpenSans.woff') format('woff');
+        src: url('./public/fonts/OpenSans.woff') format('woff');

cc: @ihmpavel

nvh95 added a commit to nvh95/vite that referenced this issue Jul 19, 2022
@sapphi-red sapphi-red linked a pull request Jul 20, 2022 that will close this issue
12 tasks
@nvh95
Copy link
Contributor

nvh95 commented Jul 29, 2022

Please update to vite >= 3.0.4 to get this issue fixed.

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

Successfully merging a pull request may close this issue.

3 participants