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
287 stars 45 forks source link

modulepreload for dynamic imports #105

Closed nboliver-ventureweb closed 1 year ago

nboliver-ventureweb commented 1 year ago

If an additional entrypoint (vite.config.js: additionalEntrypoints: ['src/js/sections/**/*.js'],) has dynamic imports, is there a way to generate a modulepreload link for them? For example in sections/hero.liquid:

{%- render 'vite-tag' with '@sections/hero.js' -%}

hero.js has a dynamic import: const { default: Splide } = await import('@splidejs/splide'); which Lighthouse is flagging as a candidate for preloading.

It seems like the entrypoint / module itself gets taken care of by the preload helper that is injected with the the vite-tag snippet, but dynamic imports aren't covered by the helper. I could be mistaken though! Any advice appreciated.

montalvomiguelo commented 1 year ago

@nboliver-ventureweb The list of chunks to preload for each dynamic import is computed by Vite https://vitejs.dev/config/build-options.html#build-modulepreload