To install SASS in Nuxt, you have to run yarn add -D sass [email protected]
(or npm i -D [email protected] --save-exact && npm i -D sass
).
The version of sass-loader
needs to be exact and set at the latest 10.x.x
because the next one (11.0.0
) is using Webpack5, hence being a breaking change because Nuxt2 is only running on Webpack4 as shown here: https://github.com/webpack-contrib/sass-loader/releases
IF then, you still cannot use <style lang="sass">
in your .vue
components, then proceed.
Add this to your nuxt.config.js
file
export default {
build: {
loaders: {
sass: {
implementation: require('sass'),
},
scss: {
implementation: require('sass'),
},
},
}
}
Here is a working repo with the latest recommended sass
(dart-sass) setup working properly with this kind of code
<template>
<div>
<span class="test">
Hello there
</span>
</div>
</template>
<style lang="sass" scoped>
div
.test
color: red
</style>
PS: if SASS is properly installed, then SCSS is working as good because it’s basically the same thing.
If you have some warning on some things being deprecated like / for divison
or any listed here: https://sass-lang.com/documentation/breaking-changes
You can refer to this answer for a fix: https://stackoverflow.com/a/68648204/8816585