barrel / shopify-vite

Modern frontend tooling for Shopify theme development using Vite for a best-in-class DX.
https://shopify-vite.barrelny.com/
MIT License
293 stars 45 forks source link

Style preloading not working #125

Closed bernier closed 7 months ago

bernier commented 7 months ago

The project mentions to use: {% render 'vite-tag' with 'theme.scss', preload_stylesheet: true %}

But the file vite-tag.liquid doesn't use the preload_stylesheet variable {{ file_url | stylesheet_tag }}

Shouldn't it be something like that instead? {{ file_url | stylesheet_tag: preload: preload_stylesheet }} Shopify docs: https://shopify.dev/docs/api/liquid/filters/stylesheet_tag

Can you do something similar for the scripts as well? https://shopify.dev/docs/api/liquid/filters/preload_tag https://shopify.dev/docs/api/liquid/filters/script_tag

montalvomiguelo commented 7 months ago

Hey, @bernier, Style preloading is working as expected. https://github.com/barrel/shopify-vite/blob/84ab7415f666a1adf71fb36cd311bca70eefa767/packages/vite-plugin-shopify/src/html.ts#L184-L185

Currently, there are no plans to preload scripts.

bernier commented 7 months ago

@montalvomiguelo Thanks. I now understand that it does add the preload when building for production. But I still see an issue with the preloading when adding multiple scripts

` render 'vite-tag' with 'styles/global.scss', preload_stylesheet: true

render 'vite-tag' with 'styles/templates/account.scss', preload_stylesheet: false `

Compiles to:

` {% if path == "/frontend/entrypoints/styles/global.scss" or path == "styles/global.scss" %}

{{ 'global.Dy9tmhrW.min.css' | asset_url | stylesheet_tag: preload: preload_stylesheet }}

{% elsif path == "/frontend/entrypoints/styles/templates/account.scss" or path == "styles/templates/account.scss" %}

{{ 'account.pJcF2Mbj.min.css' | asset_url | stylesheet_tag: preload: preload_stylesheet }}

{% endif %} `