上一期分享了如何在vue-cli3的框架中,封装mixins
,module
。本期将分享如何在vue项目中添加sass
。 css
GitHub项目地址:github.com/jiangjiahen…vue
本文默认你对sass有必定的了解,而且阅读过相关的官方文档,所以本文就不在赘述关于sass的基础知识。node
$ vue create vuedemo
? Please pick a preset: (Use arrow keys)
> default (babel, eslint)
Manually select features
复制代码
移动上下键选择Manually select features
:手动选择建立项目的特性。git
显示以下:github
? Check the features needed for your project: (Press <space> to select, <a> to t
oggle all, <i> to invert selection)
>( ) TypeScript
( ) Progressive Web App (PWA) Support
( ) Router
( ) Vuex
(*) CSS Pre-processors
( ) Linter / Formatter
( ) Unit Testing
( ) E2E Testing
复制代码
移动上下键在CSS Pre-processors
,按提示点击空格键选择CSS-processors
。web
显示以下:vue-cli
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): (Use arrow keys)
> SCSS/SASS
LESS
Stylus
复制代码
选择第一个SCSS/SASS
做为咱们的CSS
预处理器。npm
完成后项目会帮咱们安装sass-loader node-sass
。sass
若是在建立项目没有选择CSS
预处理器,咱们也能够手动安装sass-loader node-sass
来集成scss
。bash
npm install -D sass-loader node-sass
复制代码
完成添加后,咱们只须要在style
指定lang
为scss
便可,无须多余操做:
<style lang="scss" scoped>
$color: red;
h1 {
color: $color;
}
</style>
复制代码