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

Css font imports in manifest.json #18392

Open
4 tasks done
indykoning opened this issue Oct 18, 2024 · 2 comments
Open
4 tasks done

Css font imports in manifest.json #18392

indykoning opened this issue Oct 18, 2024 · 2 comments
Labels
enhancement New feature or request feat: build p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@indykoning
Copy link

indykoning commented Oct 18, 2024

Description

Currently fonts are properly added to the manifest.json but you cannot see which e.g. css/vue files require this font.
This makes automatic preloading difficult as we cannot determine which file requires the font, and IF we need to require the font for the initial page load.

https://stackblitz.com/edit/github-citlf9?file=package.json,src%2Findex.css&terminal=build

Suggested solution

I suggest adding an imports key to css files within the manifest.json just like is done with JS.
This may contain imported css (which is not relevant as everything currently gets compiled to a single css file)
and fonts required by the current css or vue file.

This way when (pre)loading the css or vue file, we know we should also (pre)load those font files

Alternative

Preloading of the fonts either needs to be done manually, or ALL fonts in the manifest.json must be loaded. Which isn't ideal since likely not all fonts are actually used on the current page.

Additional context

No response

Validations

@royduin
Copy link

royduin commented Oct 18, 2024

An example, currently the Vite just adds all the fonts with no relation to the css file where the font was discovered in the manifest:

  "resources/css/app.css": {
    "file": "assets/app-DE7dJou-.css",
    "src": "resources/css/app.css",
    "isEntry": true
  },
  "resources/css/fonts/Nunito-Bold.woff": {
    "file": "assets/Nunito-Bold-C6dW0HYt.woff",
    "src": "resources/css/fonts/Nunito-Bold.woff"
  },

Where Javascript files do have a reference with dynamic imports:

  "resources/js/app.js": {
    "file": "assets/app-CNshmeXx.js",
    "name": "app",
    "src": "resources/js/app.js",
    "isEntry": true,
    "dynamicImports": [
      "_Listing-DnGV7WH4.js"
     ],
  },
  "_Listing-DnGV7WH4.js": {
    "file": "assets/Listing-DnGV7WH4.js",
    "name": "Listing",
    "isDynamicEntry": true,
    "imports": [
      "resources/js/app.js"
    ]
  },

It would be nice to have something like:

  "resources/css/app.css": {
    "file": "assets/app-DE7dJou-.css",
    "src": "resources/css/app.css",
    "isEntry": true,
    "fonts": [
        "resources/css/fonts/Nunito-Bold.woff"
    ]
  },
  "resources/css/fonts/Nunito-Bold.woff": {
    "file": "assets/Nunito-Bold-C6dW0HYt.woff",
    "src": "resources/css/fonts/Nunito-Bold.woff",
    "foundIn": [
        "resources/css/app.css"
    ]
  },

With that we can use the new fonts array to add preload tags in the html and only get fonts from that CSS file instead of all fonts from all CSS files which aren't always used. For example multisite with a CSS per store.

Copy link

stackblitz bot commented Oct 19, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) feat: build and removed enhancement: pending triage labels Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat: build p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

No branches or pull requests

3 participants