-
|
Hi everyone, First of all I am sorry if I did not post in the right place or platform. It is related to vuetify but I genuinely think it is my vite configuration that fails. I also tried to find the answer on this forum but I did not end up to any conclusion. I’m encountering issues trying to pass to Vite (From VueCLI). Some context first. On a project I am working on, I wanted to prepare a transition to vue3 by upgrading to Vue2.7 (from 2.6) and introduce Vite. As I said, the thing I encountered is related to Vuetify: I know that with Webpack, Vuetify requires to import It is as if the files I put in additionalData are not prepend to main.scss, or any scss files in my styles folder. Maybe I didn’t understand well what additionalData does. I must be missing something but I am clueless, I would really use your help on that one. For an exemple, I forked a clean stackblitz (https://stackblitz.com/edit/vite-vuetify-global-scss-vars) and used my version in package.json + reproduced the behaviour. Here is the link : https://stackblitz.com/edit/vite-vuetify-global-scss-vars-v5adc8 In this fork I tried to override some Vuetify variables. And added a main.scss file in which I wanted to access to some Vuetify variables I have overridden. I imported this file in my I also tried to access to the same variable from a component (NestedComponent) but it does print the same error : “Undefined variable” (I know I did break the icons but this is not what I’m focused on) Thanks in advance for your help, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
|
@Doltario I'm using same approach (Vite + Vue 2.6 + Vuetify 2 + VuetifyResolver (unplugin-auto-import) + vue-demi + script setup + Pinia + unplugin pages + UnoCSS icons preset) and I use this code to configure scss/sass variables: // vite.config.ts
resolve: {
alias: {
'@/': `${path.resolve(__dirname, 'src')}/`,
},
dedupe: ['vue-demi'],
},
css: {
preprocessorOptions: {
sass: {
additionalData: [
// vuetify variable overrides
'@import "@/styles/variables.scss"', // <== your vuetify variables
'',
].join('\n'),
},
},
},I have this Vue plugin: // src/plugins/vuetify.ts
import '@/styles/app.scss'
import Vue from 'vue'
import Vuetify from 'vuetify/lib'
import messages from '@/messages' // <= custom ts module with vuetify default messages
Vue.use(Vuetify)
const opts = {
lang: {
current: 'es-ES',
defaultLocale: 'es-ES',
locales: { 'es-ES': messages },
},
theme: {
options: {
customProperties: true,
},
dark: false,
themes: {
light: {
primary: '#078930',
accent: '#fa6400',
secondary: '#424242',
info: '#2196F3',
warning: '#ffc107',
error: '#b71c1c',
success: '#4caf50',
},
},
},
}
export default new Vuetify(opts) |
Beta Was this translation helpful? Give feedback.
-
It should work: I don't use vuetify variables inside my scss files, I just override some styles, here my src/styles/variables.scss//$body-font-family: "Montserrat", sans-serif;
$font-size-root: 14px;
$color-pack: false;
$btn-font-weight: 500;
//$card-border-radius: 0;
//$card-elevation: 0;
$icon-size: 20px;
/* lists */
$list-item-dense-title-font-weight: bold;
//$list-item-dense-title-font-size: 0.9rem;
$list-dense-content-padding: 4px 0;
$icon-size-dense: 20px;
$list-dense-icon-height: 20px;
$list-dense-icon-margin: 6px;
$list-dense-min-height: 32px;
/* alerts*/
$alert-font-size: 14px;
/* tables */
$data-table-regular-header-height: 36px;
$data-table-regular-row-height: 28px;
$data-table-regular-header-font-size: 0.8rem;
$data-table-regular-row-font-size: 0.8rem;
$data-table-header-sort-badge-height: 20px;
$data-table-mobile-row-min-height: 28px;
$data-footer-font-size: 0.85rem;
$data-footer-padding: 0 8px;
$data-footer-pagination-margin-end: 0;
$data-footer-pagination-margin-start: 0;
$data-footer-select-select-margin-y: 4px;
$data-footer-select-select-margin-start: 8px;
/* toobars */
$toolbar-btn-icon-size: 20px;
$toolbar-content-padding-x: 0.5rem;
/* breadcrumbs */
$breadcrumbs-padding: 0;
$breadcrumbs-item-font-size: 17.5px;
:root {
--dark-primary-color: #3C7742;
//--primary-color: #4caf50;
//--primary-color: #3C7742;
--primary-color: #078930;
// primary-color(0.27) over white => rgb(193, 200, 227)
--primary-highlight-color: #DFF0D8;
--accent-color: #fa6400;
--accent-color-bg: rgba(255, 100, 0, 0.17);
--accent-color-fg: var(--accent-color);
//--accent-color: rgb(60, 119, 66);
// accent-color(0.27) over white => rgb(255, 213, 186)
//--highlight-color: #fa64001b;
--highlight-color: #DFF0D8;
//--highlight-color: rgb(255,238,228);
//--text-primary-color: #212121;
--text-primary-color: #ffffff;
--normal-toolbar-primary-color: #212121;
//--text-primary-color: rgba(33, 33, 33, 0.87);
//--text-primary-color: white;
--app-drawer-width: 300px;
--app-drawer-compact-width: 256px;
--error-color: #b71c1c;
--error-color-fg: var(--error-color);
--error-color-bg: #ffebee;
--success-color: #4caf50;
--success-color-fg: var(--success-color);
--info-color-bg: #E3F2FD;
--info-color-fg: #0D47A1;
// todo@quini: buscar el color para AA contrast
--success-color-bg: #4caf5070;
--warning-color: #ffc107;
--warning-color-fg: #827717;
--warning-color-bg: #ffffe7;
--app-bg-color: #e3e3e3;
/* filter */
--filter-select-width: 65px;
--filter-column-gap: 16px;
--label-color: #212121;
--picker-highlight-fgcolor: #000000;
}src/styles/app.scss@import "main";
@import "table";
@import "highlight";
@import "error";
@import "page";
@import "crud";
@import "grid";
@import "input";
@import "filter";
@import "dialog";
@import "buttons";
@import "status";
.v-dialog.crud-dialog {
background-color: white;
}
.v-data-table>.v-data-table__wrapper>table>tbody>tr>td,
.v-data-table>.v-data-table__wrapper>table>thead>tr>td,
.v-data-table>.v-data-table__wrapper>table>tfoot>tr>td,
.v-list-item--dense .v-list-item__title,
.v-list-item--dense .v-list-item__subtitle,
.v-list--dense .v-list-item .v-list-item__title,
.v-list--dense .v-list-item .v-list-item__subtitle,
.v-data-footer,
.v-data-footer__select .v-select__selection.v-select__selection--comma,
.v-data-table__mobile-row__header {
font-min-size: 12px !important;
font-size: 12px !important;
}src/styles/_main.scsshtml {
overflow-y: auto !important;
&.overflow-y-hidden {
overflow-y: hidden !important;
}
}
#app-wrapper.v-application {
&[hidden] {
display: none !important;
}
.v-list-item > .v-icon + .body-1.message-error,
.v-list-item > .v-icon + .d-sr-only + .body-1.message-error,
.v-list-item > .v-icon + .body-1.message-warning,
.v-list-item > .v-icon + .d-sr-only + .body-1.message-warning,
.v-list-item > .v-icon + .body-1.message-ok,
.v-list-item > .v-icon + .d-sr-only + .body-1.message-ok {
flex-grow: 1 !important;
}
.success--text, .error--text, .warning--text,
.message-ok, .message-error, .message-warning {
align-self: self-start;
& + .d-sr-only + .body-1 {
min-height: 32px;
align-self: self-start;
}
}
}
$color-pack: false;
/* v-toolbar */
.v-toolbar.contextual {
background-color: #dff0d8 !important;
.v-toolbar__content {
background-color: #dff0d8 !important;
color: var(--v-primary-darken1) !important;
.v-btn {
background-color: #dff0d8 !important;
color: var(--v-primary-darken1) !important;
caret-color: var(--v-primary-darken1) !important;
}
}
}
.v-toolbar__content {
padding: 0.25rem 1rem !important;
}
.v-toolbar.table .v-toolbar__content {
padding: 0 1rem 0 0.5rem !important;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
.sr-only-focusable {
&:active,
&:focus {
z-index: 4;
width: auto;
height: auto;
margin: 0 0 0 24px;
overflow: visible;
clip: auto;
font-weight: bold;
/*configure color to be the same as --app-header::color */
color: var(--text-primary-color);
}
} |
Beta Was this translation helpful? Give feedback.
-
|
So, after some further research, it seems like Vuetify doesn't load into its components the The vite.config.js should look like: For an example of the whole code I made a working reproduction: https://stackblitz.com/edit/vite-vuetify-global-scss-vars-kk2n8n Disclaimer: I don't know yet the impact on the build. but this seems to be the only and cleanest solution. |
Beta Was this translation helpful? Give feedback.
So, after some further research, it seems like Vuetify doesn't load into its components the
additionalDatadeclared insassblock. And our app's components will only load theadditionalDatadeclared inscssblock.The vite.config.js should look like: