nuxt-modules / google-fonts

Google Fonts module for NuxtJS
https://google-fonts.nuxtjs.org
MIT License
497 stars 41 forks source link

Font Not Found if changing assetFileNames to something with [hash] #201

Closed iamandrewluca closed 1 month ago

iamandrewluca commented 1 month ago

I've been trying today to change the $client rollupOptions to use only hashes in the names. Otherwise, the AdBlocker would block the chunks that they thought were ads.

Doing so (code below) all works well, but the fonts cannot be found. I need to remove the assetFileNames, and it works well.

I thought that maybe the Google Fonts module somehow needs to know about the fonts paths through the client manifest?! 🤔

export default defineNuxtConfig({
    vite: {
        $client: {
            build: {
                rollupOptions: {
                    output: {
                        chunkFileNames: '_nuxt/[hash].js',
                        entryFileNames: '_nuxt/[hash].js',
                        // This will make fonts 404 on the client
                        assetFileNames: '_nuxt/[hash][extname]',
                    },
                },
            },
        },
    },

    modules: ['@nuxtjs/google-fonts'],
    googleFonts: {
        families: {
            'Montserrat': [100, 200, 300, 400, 500, 600, 700, 800, 900],
        },
    },
});
iamandrewluca commented 1 month ago

I see that Nuxt, by default, is using only hash in filenames https://github.com/nuxt/nuxt/pull/26203, and they don't mention assets, so probably that is the correct way. Will close the issue in this case.