vue 3 sass code example
Example 1: vue scss
npm install sass-loader node-sass style-loader --save-dev
Example 2: vue import css
import '~/assets/styles.css';
<style scoped src="~/assets/styles.css"><style>
<style scoped lang="css">
@import "~/assets/styles.css";
</style>
Example 3: setup scss in vue
npm i node-sass sass-loader
–src
|––styles
|––main.scss
module.exports = {
css: {
loaderOptions: {
sass: {
prependData: `@import "@/styles/_variables.scss";`
}
}
}
};
Example 4: vue js sass
# /!\ if you work with vue@2.6.12, it seems sass-loader@11.0.0 doesn't work
# So, in terminal:
yarn add node-sass sass-loader@10.1.1
Example 5: vue add sass
<!--
# Run this command in the root dir of your vue project:
npm i sass-loader node-sass style-loader
-->
<!-- And later in your vue component -->
<style lang="sass">
</style>