vue2项目使用sass的示例代码
1,使用save会在package.json中自动添加。
npm install node-sass --save-dev npm install sass-loader --save-dev
注:
通常使用npm安装会出现以下报错,安装失败。(网路问题)
可以通过淘宝的npm镜像安装node-sass,解决以上问题。
$ npm install -g cnpm --registry=https://registry.npm.taobao.org (安装淘宝镜像) $ cnpm install node-sass --save (使用淘宝镜像安装node-sass)
2.进入webpack.base.config.js 配置scss module -- loaders (vue1.0)
$ npm install --save-dev sass-loader style-loader css-loader
{ test: /\.vue$/, loader: 'vue-loader', options: { loaders: { 'scss': 'style-loader!css-loader!sass-loader' } } }
打开webpack.base.config.js在loaders里面加上 module -- rules (vue2.0)
rules: [ { test: /\.vue$/, loader: 'vue-loader', options: vueLoaderConfig }, { test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test')] }, { test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', query: { limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } }, { test: /\.scss$/, loaders: ["style", "css", "sass"] }, { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url-loader', query: { limit: 10000, name: utils.assetsPath('fonts/[name].[hash:7].[ext]') } } ] }
3.如果需要在vue文件style标签使用scss的话,需要声明一下:
vue1.0
<style rel="stylesheet/scss" lang="scss"></style>
vue2.0
<style lang="scss" scoped="" type="text/css"></style>
相关推荐
RedCode 2020-10-28
teresalxm 2020-06-05
沈宫新 2020-05-28
dazhifu 2020-05-19
buttonChan 2020-05-10
nicepainkiller 2020-02-23
vavid 2020-02-15
tianzyc 2020-02-01
nicepainkiller 2020-01-29
dazhifu 2020-01-25
CaiKanXP 2020-01-08
葉無聞 2019-12-30
waterv 2019-12-27
福叔 2019-12-27
swiftwwj 2019-12-27
MaureenChen 2019-12-26