Skip to content

Global scss variables and mixins #4750

@chris-dura

Description

@chris-dura

Version

4.0.5

Reproduction link

https://github.com/chris-dura/vue-cli-4-0-5

Environment info

Environment Info:

  System:
    OS: macOS Mojave 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-4960HQ CPU @ 2.60GHz
  Binaries:
    Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
    Yarn: 1.16.0 - ~/.yarn/bin/yarn
    npm: 6.12.0 - ~/.nvm/versions/node/v12.13.0/bin/npm
  Browsers:
    Chrome: 77.0.3865.120
    Firefox: 64.0
    Safari: 12.1.1
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0 
    @vue/babel-plugin-transform-vue-jsx:  1.0.0 
    @vue/babel-preset-app:  4.0.5 
    @vue/babel-preset-jsx:  1.1.1 
    @vue/babel-sugar-functional-vue:  1.0.0 
    @vue/babel-sugar-inject-h:  1.0.0 
    @vue/babel-sugar-v-model:  1.1.1 
    @vue/babel-sugar-v-on:  1.1.0 
    @vue/cli-overlay:  4.0.5 
    @vue/cli-plugin-babel: ^4.0.0 => 4.0.5 
    @vue/cli-plugin-eslint: ^4.0.0 => 4.0.5 
    @vue/cli-plugin-router: ^4.0.0 => 4.0.5 
    @vue/cli-plugin-typescript: ^4.0.0 => 4.0.5 
    @vue/cli-plugin-vuex: ^4.0.0 => 4.0.5 
    @vue/cli-service: ^4.0.0 => 4.0.5 
    @vue/cli-shared-utils:  4.0.5 
    @vue/component-compiler-utils:  3.0.0 
    @vue/eslint-config-standard: ^4.0.0 => 4.0.0 
    @vue/eslint-config-typescript: ^4.0.0 => 4.0.0 
    @vue/preload-webpack-plugin:  1.1.1 
    @vue/web-component-wrapper:  1.2.0 
    eslint-plugin-vue: ^5.0.0 => 5.2.3 
    typescript: ~3.5.3 => 3.5.3 
    vue: ^2.6.10 => 2.6.10 
    vue-class-component: ^7.0.2 => 7.1.0 
    vue-eslint-parser:  5.0.0 
    vue-hot-reload-api:  2.3.4 
    vue-loader:  15.7.1 
    vue-property-decorator: ^8.3.0 => 8.3.0 
    vue-router: ^3.1.3 => 3.1.3 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.6.10 => 2.6.10 
    vue-template-es2015-compiler:  1.9.1 
    vuex: ^3.0.1 => 3.1.1 
  npmGlobalPackages:
    @vue/cli: 4.0.5

Steps to reproduce

  1. vue create my-project
  2. Create src/scss/_variables.scss file with a $some-color variable
  3. Reference $some-color in HelloWorld.vue styles
  4. Pass prependData: '@import "~@/scss/_variables.scss";' to sass-loader options in vue.config.js

What is expected?

The scss for HelloWorld.vue compiles with no errors.

What is actually happening?

A scss compile error:

SassError: Undefined variable.
   ╷
51 │   color: $some-color;
   │          ^^^^^^^^^^^
   ╵

Initially, I tried to load a global stylesheet from my node_modules folder, and at first, thought that was why it wasn't working. There were a lot of issues and discussion already on GitHub, however, the solutions didn't work for me, even after simplifying it to just pull in from the src folder like everyone else was doing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions