A
A
Alexey Orlov2020-11-18 15:45:12
Vue.js
Alexey Orlov, 2020-11-18 15:45:12

Connecting styles globally in vue?

I created the styles directive in assets with the main.styl file, into which I import global style files (fonts, grid, variables, mixins, resets). But files only work in component styles (scoped), not globally.
I include main.style automatically in vue.config.js:

const path = require('path')

module.exports = {
  pluginOptions: {
    'style-resources-loader': {
      'preProcessor': 'stylus',
      'patterns': [
        path.resolve(__dirname, './src/assets/styles/main.styl')
      ]
    }
  }
}

At the same time, if you import this file into main.js, or remove scoped, then everything works, but there is duplication and repetition of styles. And styles are connected as many times as they are in components. (Example in the picture, inside the same styles).

b23366b81693354e796bc0140fe38f2d.png

How to fix this problem so that global styles work regardless of whether they are used in components or not?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Orlov, 2020-11-18
@LeshaGFB

UPD. I found a solution, connect files with fonts and reset directly in App.vue. Leave the rest in main.styl, which will be connected as needed in the components. Is this decision correct?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question