vuetify-module icon indicating copy to clipboard operation
vuetify-module copied to clipboard

CustomVariables not overriding Vuetify variables

Open Pernick opened this issue 7 years ago • 23 comments

Module version v1.9.0

Describe the bug Variables defined in variables.scss are not overriding vuetify variables

To Reproduce https://github.com/Pernick/custom-variables-test

Steps to reproduce the behavior:

  1. Clone the repository
  2. npm install
  3. npm run dev
  4. Try to change the $body-font-family variable in assets/variables.scss

Expected behavior Font changing based on the variable

Additional context This was working before the update - I think the version was ~1.5.0. Manually setting font-family css on the element works fine.

Pernick avatar Oct 11 '19 09:10 Pernick

For me, it works in this way:

$body-font-family: 'Work Sans', sans-serif;
@import '~vuetify/src/styles/main.sass';

But I don't really know if it is good to import main.sass. But works!

EDIT: Sorry, that doesn't work when you do npm run build.

enzonotario avatar Oct 15 '19 21:10 enzonotario

@Pernick Did you try https://github.com/nuxt-community/vuetify-module#defaultassets font option ? I'll take a look when I've some time

kevinmarrec avatar Oct 16 '19 08:10 kevinmarrec

@kevinmarrec Yes I have. Setting the

font: {
    family: 'Montserrat' 
},

in default assets doesn't seem to be doing the job either unfortunatelly.

Pernick avatar Oct 16 '19 08:10 Pernick

For me it does work using:

vuetify: {
    customVariables: ["~/styles/variables.scss"],
    treeShake: true,
    options: {
          customProperties: true
     }
}

I can change the font-size or font family, are you sure the font is actually loaded in? I do have an issue however that i can't seem to be changing a few variables like the background color... it won't override that for me :/

thebspin avatar Oct 16 '19 13:10 thebspin

@thebspin Yes, you can see in the issue - changing the font-family style property manually on the element works fine. You can see the options in the repo I provided.

Pernick avatar Oct 16 '19 13:10 Pernick

I faced the same problem,finally solve this with by doing these:

  • installed "nuxt-webfontlodaer" learning from Developmint/nuxt-webfontloader using npm i nuxt-webfontloader
  • then added the module in nuxt.config.js webfontloader: { custom: { families: [ 'Raleway:400,900', 'Lato:400,700,900' ], urls: [ 'https://fonts.googleapis.com/css?family=Raleway:400,900&display=swap', 'https://fonts.googleapis.com/css?family=Lato:400,700,900&display=swap' ] } },

-then added the font in the vuetify module: vuetify: { defaultAssets: { font: { family: 'Lato' }, icons: 'mdi' }, treeShake: true, options: { customProperties: true } },

mimbo119 avatar Oct 23 '19 06:10 mimbo119

@mimbo119 Thanks for your input. Unfortunately this does not solve the issue for me. I updated the test repo with this change (https://github.com/Pernick/custom-variables-test). I was using webfontloader from the beginning, although I used it with

webfontloader: {
    google: { ... }
}

options instead of custom. Trying the custom fonts is not working either. (I removed all the caches, too).

Pernick avatar Oct 23 '19 06:10 Pernick

@Pernick See https://github.com/nuxt-community/vuetify-module/releases/tag/v2.0.0-alpha.0

Using :

vuetify: {
    defaultAssets: {
      font: {
        family: 'Montserrat',
        size: 20
      }
    }
  }

It just works for me, using nuxt-webfontloader, both with nuxt dev & nuxt build + nuxt start.

See https://github.com/nuxt-community/vuetify-module/tree/next/test/fixture

kevinmarrec avatar Nov 04 '19 01:11 kevinmarrec

@kevinmarrec I am starting to suspect, the issue lays somewhere else. Because even this is not working for me. I updated the test repo - it is pretty bare bones, so I don't see what could be the issue there.

Setting defaultAssets is not working. Customizing customVariables file is not working. Screenshot 2019-11-04 at 13 33 06

Pernick avatar Nov 04 '19 12:11 Pernick

Okay, I've found the reason. Upgrading sass-loader solved the issue. Thanks everyone for their inputs and time.

Pernick avatar Nov 04 '19 12:11 Pernick

I'm still having this issue with nuxt 2.11.0 - I would go with the font loader module, by would I have to do that if I import in the css and declare the font family? What I'm doing SHOULD work and there shouldn't be a whole package imported just to get this one font to work.

My project already has a ton of imports lol.

// nuxt.config.js
buildModules: [
	...
	'@nuxtjs/vuetify',
	...
],

modules: [
	...
	'@nuxtjs/style-resources',
	...
],
vuetify: {
	treeShake: true,
	defaultAssets : {
		font: {
			family: "Montserrat",
		},
		icons: "mdi",
	},
	customVariables: ['~/assets/scss/variables.scss'],
},
/* file: ~/assets/scss/variables.scss */

/* Ref: https://github.com/nuxt-community/vuetify-module#customvariables */

@import url('https://fonts.googleapis.com/css?family=Montserrat:400,500,600,700&display=swap');

$body-font-family: 'Montserrat', sans-serif !important;
$heading-font-family: 'Montserrat', sans-serif !important;

@import '~vuetify/src/styles/styles.sass';

Then in the inspector, there's no styling at all for applying the font family.

image

// package.json
{
  "dependencies": {
    "@nuxtjs/style-resources": "^1.0.0",
    ...
    "node-sass": "^4.13.1",
    "sass-loader": "^7.1.0"
    ...
  },
  "devDependencies": {
    ...
    "@nuxtjs/vuetify": "^1.0.0",
    ...
  }
}

zacharytyhacz avatar Feb 03 '20 15:02 zacharytyhacz

Okay, I've found the reason. Upgrading sass-loader solved the issue. Thanks everyone for their inputs and time.

@Pernick you save my day 👍

armadillo-dev avatar Apr 20 '20 09:04 armadillo-dev

Hi Guys,

If you are using nuxt, you need to install those packages:

npm install sass sass-loader@8 fibers deepmerge -D

Running this command will make everything work ;)

dawidstefaniak avatar Sep 05 '20 17:09 dawidstefaniak

Yea, it only works with sass-loader@^8.0.2 (not v9 or v10) :(

tomexx avatar Sep 17 '20 16:09 tomexx

dont forget treeShake: true,

vuetify: {
    customVariables: ["~/assets/variables.scss"],
    treeShake: true,
    }

copy-ninja1 avatar Oct 02 '20 01:10 copy-ninja1

Related to: Storybook Vuetify Vuetify Custom Variables

I believe that Storybook has a bug, importing incorrectly the variables.scss file and apply it to Vuetify. And the bug is based on that: Vuetify is loaded earlier than the custom variables.scss file... So it's actually imported correctly, but the variables won't be overwritten.

https://github.com/nuxt-community/vuetify-module/issues/191#issuecomment-542404033 mentions a work around which actually works for me. At the end of the variables.scss file, add @import '~vuetify/src/styles/main.sass'; But it makes the normal app to be loading the main.sass file like 100 times.... so it's not really a good workaround. So you can rather just create another sb-variables.scss file, where you can import these two files in the right order!!, like:

@import "@/styles/variables.scss";
@import '~vuetify/src/styles/main.sass';

Also, this is only enough for global variables. If you want to use the styles of Vuetify components, sadly you have to import them after one by one: @import '~vuetify/src/components/VInput/VInput.sass';

azollai avatar Oct 26 '20 14:10 azollai

For me declaring treeShake and customVariables directly in the nuxt.config.js instead of the optionsPath file (can still declare colors there tho) worked..

bhaskar-nair2 avatar Dec 09 '20 14:12 bhaskar-nair2

@dawidstefaniak Tnx it work sass-loader@8 just

mansorygit avatar Dec 28 '20 03:12 mansorygit

Is there a way to override primary color using scss variables?

QuipHop avatar Jan 13 '21 08:01 QuipHop

Is there a way to override primary color using scss variables?

@QuipHop You can just set it in the vuetify.options.js file

bhaskar-nair2 avatar Jan 13 '21 09:01 bhaskar-nair2