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

Vuetify 3 styles missing in the production build #187

Open
pferreirafabricio opened this issue Aug 4, 2023 · 6 comments
Open

Vuetify 3 styles missing in the production build #187

pferreirafabricio opened this issue Aug 4, 2023 · 6 comments

Comments

@pferreirafabricio
Copy link

pferreirafabricio commented Aug 4, 2023

Hi!
I was having some trouble using this plugin along with Vuetify. For some reason, when I ran npm run build most of the CSS of the components that I was using on my page was not loaded.
After some hours I decided to generate a build without the nuxt-purgecss inside the modules array, and then the styles of the components are showing correctly.

nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
import vuetify from "vite-plugin-vuetify";

export default defineNuxtConfig({
  devtools: { enabled: true },
  build: {
    transpile: ["vue-toastification", "vuetify"],
  },
  modules: [
    "@nuxt/image",
    "@pinia/nuxt",
    "@pinia-plugin-persistedstate/nuxt",
    "@nuxtjs/robots",
    "nuxt-icon",
    // eslint-disable-next-line require-await
    async (_options, nuxt) => {
      nuxt.hooks.hook("vite:extendConfig", (config) =>
        // @ts-ignore
        config.plugins.push(vuetify()),
      );
    },
  ],
  vite: {
    ssr: {
      noExternal: ["vuetify"],
    },
  },
  typescript: {
    shim: false,
  },
  css: [
    "vuetify/lib/styles/main.sass",
    "@mdi/font/css/materialdesignicons.min.css",
  ],
  experimental: {
    inlineSSRStyles: false,
  },
});

package.json:

"devDependencies": {
  "@nuxt/devtools": "latest",
  "@types/node": "^18.16.19",
  "nuxt": "^3.6.2",
  "nuxt-purgecss": "^2.0.0",
  "vite-plugin-vuetify": "^1.0.2",
  "sass": "^1.64.2"
},
"dependencies": {
  "vuetify": "^3.3.11",
  "@mdi/font": "^7.2.96"
}

In dev:

In production build:

@pferreirafabricio
Copy link
Author

pferreirafabricio commented Aug 4, 2023

One solution that I've found is putting the reference to Vuetify CSS directly inside the head tag (in the nuxt.config.ts), something like this:

app: {
    head: {
      link: [
        {
          rel: "stylesheet",
          href: "https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css",
        },
      ],
    },
  },

But certainly not optimal.

Reference: nuxt/nuxt#5966 (comment)

@pferreirafabricio pferreirafabricio changed the title Vuetify 3 styles missing in production build Vuetify 3 styles missing in the production build Aug 10, 2023
@pferreirafabricio
Copy link
Author

pferreirafabricio commented Aug 10, 2023

I've made a repository to exemplify this bug with the minimal configurations: https://github.com/pferreirafabricio/issue-nuxt-vuetify-purgecss
Also, it can be accessed in CodeSandbox: https://codesandbox.io/p/github/pferreirafabricio/issue-nuxt-vuetify-purgecss/main

I hope it helps!

@Buczek05
Copy link

I have the same problem

@ae-daenchrisarmada
Copy link

In my case, I just removed/commented the nuxt-purgecss under the buildModules then everything worked like a charm.

@pferreirafabricio
Copy link
Author

In my case, I just removed/commented the nuxt-purgecss under the buildModules then everything worked like a charm.

Yeah, that was my solution, but remember that now you have unpurged CSS.

@ae-daenchrisarmada
Copy link

Hello @pferreirafabricio

It is a lot better than "not working at all"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants