question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using SCSS in Vue components

See original GitHub issue

I’m looking for a way to tell laravel-mix to use the sass-loader when it comes across the following in a Vue component.

<style lang="scss">
   // random scss
</style>

The issue at hand is that there isn’t really an scss-loader. sass-loader is used for both scss and sass, however by default whenever vue-loader sees lang="scss" it tries to find scss-loader.

I could just use lang="sass", however this causes most text editors to highlight (would-be) sass errors.

When using laravel-elixir I’m able to get around this by adding the following snippet to my webpack.config.js file.

module.exports = {
  vue: {
    loaders: {
      js: 'buble-loader',
      scss: 'vue-style-loader!css-loader!sass-loader'
    }
  }
}

I’m currently using the mix.webpackConfig method to change other configuration, however I’m not sure what options I need to pass in to accomplish my goals.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

35reactions
JeffreyWaycommented, Jan 4, 2017

Hey guys, I’ve updated the webpack.config.js to allow for specifying:

<style lang="sass">
    $primary: red

    #thing
        background: $primary
</style>

Or:

<style lang="scss">
    $primary: red;

    #thing {
        background: $primary;
    }
</style>
1reaction
trekzecommented, Feb 18, 2019

@ruchern Apologies for the necro. Is this a bad practice to do in every component? Is webpack smart enough to not reduplicate importing that css for everything? Uncertain of what’s going on when I go with this approach, but I haven’t found any other solution. I don’t like cluttering my vue templates with col-xs-12 and so forth, so I prefer to use mixins and keep my classes semantic.

6 months later, someone walks by and wonders the same thing a @laaksomavrick

Is it ok to import bootstrap scss in every styled component, or is that duplicating a whole bunch of css that ends up in the bundle?! Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use SCSS with Vue.js Single File Components
Find out how to enable SCSS into your Vue.js components.
Read more >
Using Pre-Processors - Vue Loader - Vue.js
It will automatically infer the proper loaders to use based on the lang attribute of a language block and the rules in your...
Read more >
Automatically import SASS/SCSS into every Vue.js component
The good news is that the Vue CLI makes it incredibly easy to support writing SCSS, and with Vue's single file components you...
Read more >
Today I Learned: Using SCSS in your Vue Components
Styling your Vue components with SCSS is incredibly simple – provided you have the right configuration. const VueLoaderPlugin = require('vue- ...
Read more >
Globally Load SASS into your Vue.js Applications
Loading global SASS in the vue-cli ... Vue-cli allows to modify its configuration by creating a vue.config.js file at the root of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found