Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SASS / SCSS with latest vue-cli starter project?

I need to use SASS or SCSS in my project.

I used the vue-cli to make the latest version of a starter project.

Anyone had any success in making sass/scss work in the newest starter project with webpack?

like image 457
CommonSenseCode Avatar asked May 17 '17 08:05

CommonSenseCode


People also ask

How do I add SCSS to Vue component?

You have SCSS variables in one file that you want to make available to your Vue components. The good news is that the Vue CLI makes it incredibly easy to support writing SCSS, and with Vue's single file components you can simply add lang="scss" to the <style> block (docs).


2 Answers

  1. you install the necessary dependencies

    npm install -D node-sass sass-loader

  2. for global styles, simply import the file into main.js:

    import './styles/my-styles.scss'

  3. in .vue files, add the lang to the <style> element.

    <style lang="scss">

If using webstorm:

<style lang="scss" rel="stylesheet/scss">

like image 63
Linus Borg Avatar answered Sep 18 '22 04:09

Linus Borg


As Latest documentation of @vue/cli-service": "^3.9.0", first need to install two npm dev dependencies i.e. sass, sass-loader

Sass

npm install -D sass-loader sass

yarn add --dev sass-loader sass

Then you can import the corresponding file types, or use them in *.vue files with:

<style lang="scss">   $color: red; </style> 

Refer to latest documentation here

like image 20
Prafull Sharma Avatar answered Sep 20 '22 04:09

Prafull Sharma