14

I am using Vue CLI 3 and Vuetify 2.1 in a new-ish project, and recently delved into overriding Vuetify's SASS variables. After finally getting it to work, I realized that each time I modify the variables.scss file that I created and the project recompiles, it takes close to 5 minutes to finish compiling. I've tried updating the package.json script to bump up the memory that Node is using, and while that fixed an error I was receiving that caused the compile to crash, the result is now extremely slow compile times. The progress that shows (I'm using Foreman to run both my Rails API and Vue server at the same time) looks like this:

17:47:29 web.1  | <s> [webpack.Progress] 69% building 916/930 modules 14 active /<path/to/app>/frontend/node_modules/css-loader/index.js??ref--9-oneOf-3-1!/<path/to/app>/frontend/node_modules/postcss-loader/src/index.js??ref--9-oneOf-3-2!/<path/to/app>/frontend/node_modules/sass-loader/lib/loader.js??ref--9-oneOf-3-3!/<path/to/app>/frontend/node_modules/vuetify/src/components/VSwitch/VSwitch.sass

These progresses load, like I mentioned, for about five minutes before it finally finishes. My guess is that because I updated a variable, it's having to go through and update that style for each component and instance of that variable in the Vuetify node_module.

My question is whether there is any way to speed this up? Maybe I've set something up wrong that has caused this issue? Or is this totally normal and I'll just have to deal with it?

main.js

import Vue from 'vue';

import App from './App.vue';
import { router } from './router';
import store from './_store';
import vuetify from './plugins/vuetify';

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  vuetify,
  render: h => h(App),
}).$mount('#app');

vuetify.js

import 'material-design-icons-iconfont/dist/material-design-icons.css';
import Vue from 'vue';
import Vuetify from 'vuetify/lib';

Vue.use(Vuetify);

export default new Vuetify({
  theme: {
    options: {
      customProperties: true,
    },
    themes: {
      light: {
        primary: '#4A90E2',
        darkPrimary: '#3B73B4',
        secondary: '#424242',
        accent: '#82B1FF',
        error: '#a70000',
        info: '#2196F3',
        success: '#4CAF50',
        warning: '#FFC107',
        teal: '#64EBC6',
        green: '#7ED321',
        darkGreen: '#4c8f1d',
        lightGrey: 'rgba(0,0,0,0.12)',
        darkGrey: '#4A4A4A',
        textSecondary: 'rgba(0,0,0,0.4)',
      },
    },
  },
  icons: {
    iconfont: 'md',
  },
});

variables.scss

// Globals
$border-radius-root: 2px;
// $font-size-root: 14px;
$body-font-family: 'Avenir Next', 'Lato', Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif; // $main-font comes from my own ./_variables.scss.
$heading-font-family: 'Avenir Next', 'Lato', Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif; // $title-font comes from my own ./_variables.scss.

$headings: (
  'h1': (
    'size': 3.3125rem,
    'line-height': 1.15em
  ),
  'h2': (
    'size': 2.25rem,
    'line-height': 1.5em,
  ),
  'h3': (
    'size': 1.5625rem,
    'line-height': 1.4em
  ),
  'h4': (
    'size': 1.125rem,
    'line-height': 1.4em
  ),
  'h5': (
    'size': 1.0625rem
  ),
  'h6': (
    'size': .75rem
  ),
  'subtitle-2': (
    'size': 1rem
  ),
  'overline': (
    'letter-spacing': 0
  )
);

@import '~vuetify/src/styles/settings/variables';

// V-Btn
$btn-letter-spacing: 1px;
@import '~vuetify/src/components/VBtn/_variables';

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

package.json

{
  "name": "myProject",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve" : "node --max_old_space_size=4096 node_modules/.bin/vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "core-js": "^2.6.5",
    "dayjs": "^1.8.16",
    "echarts": "^4.3.0",
    "fibers": "^4.0.1",
    "material-design-icons-iconfont": "^5.0.1",
    "sass": "^1.23.0",
    "sass-loader": "7.1.0",
    "vee-validate": "^3.0.11",
    "vue": "^2.6.10",
    "vue-router": "^3.0.3",
    "vuedraggable": "^2.23.2",
    "vuetify": "^2.1.0",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.12.0",
    "@vue/cli-plugin-eslint": "^3.12.0",
    "@vue/cli-service": "^3.12.0",
    "@vue/eslint-config-airbnb": "^4.0.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.0.0",
    "vue-cli-plugin-vuetify": "^1.0.1",
    "vue-template-compiler": "^2.6.10",
    "vuetify-loader": "^1.2.2"
  }
}
J. Jackson
  • 3,326
  • 8
  • 34
  • 74
  • I'm experiencing similar problems with build time when setting Sass variables like this. I also found somebody else experiencing slow build times here https://github.com/vuetifyjs/vuetify/issues/9323#issuecomment-540984585. I wouldn't say it was 'normal' at all and I'm trying to create a reduced use case now to raise an issue on the vuetify github – mattGreenfield Oct 22 '19 at 15:02
  • Fantastic, thanks for the response! I'll follow along with that issue and see what becomes of it. Thanks again! – J. Jackson Oct 23 '19 at 16:04
  • 1
    Having the exact same issue. Removing the sass variables file make everything work fast again. – Zaptree Oct 25 '19 at 18:21
  • It's worth keep track of this issue on github - https://github.com/vuetifyjs/vue-cli-plugin-vuetify/issues/133 – mattGreenfield Nov 07 '19 at 09:05
  • 1
    I've raised a new issue as I've tried everything and it's still slow https://github.com/vuetifyjs/vuetify-loader/issues/95 – mattGreenfield Nov 07 '19 at 12:07
  • 1
    We had same problem. Build time for both development and production were huge. Also `vuetify-loader` has a number of bugs so we decided to use full vuetify installation without SASS variables and `vuetify-loader`. Changes are significant - our build time reduced from 6min to <2min and development server starts in 15 seconds with quite fast hot reloading. Anyway, by deleting `sass/variables.scss` we've made our build fast again. – Andriy Lach Nov 27 '19 at 10:24

1 Answers1

5

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

This injects a fairly large amount of CSS into the top of every single sass file, so it gets repeated a couple hundred times. The variables file should not contain any code that outputs actual styles - only variables, mixins, and functions are allowed.

30+ sec when modifying the variables file is normal however, as you guessed it has to recompile everything in that case. Importing from vuetify/lib/framework instead of vuetify/lib may speed this up somewhat by only including used components in the dev bundle.

Kael Watts-Deuchar
  • 4,213
  • 1
  • 26
  • 50
  • "vuetify/lib/framework instead of vuetify/lib" -- seems to be a great recommendation, compiled almost twice as fast when restarting the dev server. – Liebster Kamerad Jul 22 '20 at 13:24
  • 1
    Unfortunately it causes this problem: https://stackoverflow.com/questions/65172139/could-not-find-a-declaration-file-for-module-vuetify-lib-framework/65172140 – some-user Dec 28 '20 at 18:33
  • `vuetify/lib` is the same as `vuetify/lib/framework`. I guess this hasn't always been the case but it is now. (The default export of `vuetify/lib` is `vuetify/lib/framework`) – Hamish Jun 01 '21 at 09:52
  • It isn't exactly the same, `vuetify/lib` also re-exports all the components and directives. – Kael Watts-Deuchar Jun 01 '21 at 11:02