I'm trying to migrate a Vue2+Vuetify app from Vue-CLI/Webpack to Vite. The app has a couple of SCSS files, main.scss and variables.scss with the latter imported by the former.
main.scss
@import 'variables';
// global style rules (omitted)
variables.scss
// override some Vuetify variables and define some variables of my own, e.g.
// Vuetify default is 48px
$data-table-mobile-row-min-height: 32px;
// Increase default height by 10px
// https://vuetifyjs.com/en/api/v-date-picker/#sass-variables
$date-picker-table-height: 252px;
main.scss is imported in the root component, which means that:
- rules in
main.scssare applied to every component - variables in
variables.scsscan be referred to in any component without any additional imports - variables defined by Vuetify can be referred to in any component without any additional imports
- variables in
variables.scssoverride Vuetify variables with the same name
However, after migrating to Vite, only (1) still worked. I was able to resolve (2) and (3) by adding the following to vite.config.js
export default defineConfig({
// other config omitted
css: {
preprocessorOptions: {
scss: {
// Make the variables defined in these files available to all components, without requiring an explicit
// @import of the files themselves
additionalData: `@import "./src/styles/variables"; @import "vuetify/src/styles/settings/_variables";`
},
},
},
});
However, it's still the case that (4) no longer works.
As far as I know, the vuetify-loader is responsible for this behaviour when building with Vue-CLI, but it's not clear how to override Vuetify variables when building with Vite?