如何在vue项目中使用sass(scss)

1.用npm/cnpm/yarn安装sass的依赖包

npm install --save-dev sass-loader

npm install --save-dev node-sass

或者:

yarn add sass-loader node-sass

2.在build目类下找到webpack.base.conf.js文件,在module的rules中插入以下代码:

module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},

 

posted @ 2019-06-25 14:42  wjs0509  阅读(2620)  评论(0编辑  收藏  举报