Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implicitly load global SCSS files in Vue Single File Components? #1024

Closed
corysimmons opened this issue Jul 20, 2017 · 1 comment
Closed

Comments

@corysimmons
Copy link

  • Laravel Mix Version: 1.2.2
  • Node Version (node -v): v7.4.0
  • NPM Version (npm -v): 5.2.0
  • OS: macOS Sierra

Description:

I'd like to be able to import a couple Sass files globally: https://vue-loader.vuejs.org/en/configurations/pre-processors.html#loading-a-global-settings-file

I can do this by explicitly defining the @import in each .vue file, but this is pretty brittle (if I move some .scss into a new directory my @imports will break).

Come to think of it, I probably won't be migrating these really generic .scss files much, but at this point I'm just curious.

I tried:

let mix = require('laravel-mix');
const path = require('path')

mix
  .js('resources/assets/js/app.js', 'public/js')
  .sass('resources/assets/sass/app.scss', 'public/css')
  .webpackConfig({
    module: {
      rules: [
        {
          test: /\.vue$/,
          exclude: /(node_modules|bower_components)/,
          loader: 'sass-resources-loader',
          options: {
            resources: path.resolve(__dirname, 'resources/assets/sass/_variables.scss')
          }
        }
      ]
    }
  })

...per:

...but kept running into:

 error  in ./resources/assets/js/components/Foo.vue

Module build failed:
undefined
             ^
      Undefined variable: "$fav-color".
      in /Users/yo/Desktop/Blah/resources/assets/js/components/Foo.vue (line 89, column 15)

($fav-color exists in _variables.scss)

I suspect the problem lies somewhere in your webpack-rules.js, but haven't really tinkered with it.

Feel free not to worry about this, but it might be nice to add vue-loader's official solution to Mix.

Thanks for all your hard work. Grats on the kiddo.

@JeffreyWay
Copy link
Collaborator

Closing this in favor of the PR. #1163

JeffreyWay added a commit that referenced this issue Nov 6, 2017
#1024 Add globalVueStyles configuration option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants