feat-agency / vite-plugin-webfont-dl

⚡ Webfont Download Vite Plugin - Make your Vite site load faster
MIT License
302 stars 11 forks source link

Only injects into one html file. #30

Closed simonbuchan closed 1 year ago

simonbuchan commented 1 year ago

If you have a build that creates multiple html output files then this plugin will only inject the style / css link tag into the last one it sees.

In a real project this happens with a plugin scraping your source files for e.g. a foo.page.tsx and generating an entry from a template html file, but you can reproduce the issue with the simple manual config:

import { defineConfig } from "vite";
import { viteWebfontDl } from "vite-plugin-webfont-dl";

export default defineConfig({
    build: {
        rollupOptions: {
            input: {
                index: "index.html",
                other: "other.html",
            },
        },
    },
    plugins: [
        viteWebfontDl([
            "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap",
        ])
    ],
});

This is due to the plugin storing only a indexHtmlContent/Path in transformIndexHtml() and updating it in generateBundle(), but this config will fire the transformIndexHtml() for every input html file (despite the name) first.

0xb4lint commented 1 year ago

Thanks @simonbuchan for bringing attention for this behaviour, we'll definitely look into that and fix it!

0xb4lint commented 1 year ago

Just released v3.7.4 with multiple html files support.

I hope it works for you as expected. 😉

simonbuchan commented 1 year ago

Works perfectly! Thanks for the quick turnaround, you really saved me some time!