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

Viewed 44092

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?

3 Answers

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

Add this in your package.json in scripts and run

"compile:sass": "node-sass 'your main scss file location' 'your compiled css file location' -w"

Please make sure that node-sass and sass-loader are added properly.

And then in you App.vue file add this, then run

<style lang="scss">

    @import 'your compiled css file location';

</style>

This works for me.

Thanks

Related