在Vue项目中使用Sass

1.引入sass
使用save会在package.json中自动添加。

npm install node-sass --save-dev 
npm install sass-loader --save-dev 

2.进入webpack.base.config.js 在loaders里面加上module–rules

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的话,需要声明一下:
vue2+

<style lang="scss" scoped="" ></style>

转载:https://www.cnblogs.com/crazycode2/p/6535105.html

猜你喜欢

转载自blog.csdn.net/weixin_39407291/article/details/90083518